Check-in [ba3430c2d6]
Overview
Comment:Updated to deal with erroptname more completely
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: ba3430c2d61baec2673c15153f1615a1ad345c3f
User & Date: rkeene on 2014-11-25 18:03:58
Other Links: manifest | tags
Context
2014-11-25
18:04
Updated test driver to be completely leak-free check-in: cb9ab48b6d user: rkeene tags: trunk
18:03
Updated to deal with erroptname more completely check-in: ba3430c2d6 user: rkeene tags: trunk
2014-11-24
22:35
Updated to use ABI version for soname check-in: d26243325f user: rkeene tags: trunk
Changes

Modified libconfig.c from [fc4f4efc0c] to [7a2236b6e0].

636
637
638
639
640
641
642

643
644
645
646
647
648
649
650
651
652
653

654
655
656
657
658
659
660
	local_lc_errline = 0;

	/* Allocate "argc + 1" (+1 for the NULL terminator) elements. */
	newargv = malloc((argc + 1) * sizeof(*newargv));
	if (newargv == NULL) {
		lc_errfile = local_lc_errfile;
		lc_errline = local_lc_errline;

		lc_errno = LC_ERR_ENOMEM;
		return(-1);
	}
	newargv[newargvidx++] = argv[0];
	newargv[argc] = NULL;

	/* Allocate space to indicate which arguments have been used. */
	usedargv = malloc(argc * sizeof(*usedargv));
	if (usedargv == NULL) {
		lc_errfile = local_lc_errfile;
		lc_errline = local_lc_errline;

		lc_errno = LC_ERR_ENOMEM;
		free(newargv);
		return(-1);
	}
	for (cmdargidx = 0; cmdargidx < argc; cmdargidx++) {
		usedargv[cmdargidx] = 0;
	}







>











>







636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
	local_lc_errline = 0;

	/* Allocate "argc + 1" (+1 for the NULL terminator) elements. */
	newargv = malloc((argc + 1) * sizeof(*newargv));
	if (newargv == NULL) {
		lc_errfile = local_lc_errfile;
		lc_errline = local_lc_errline;
		lc_erroptname = NULL;
		lc_errno = LC_ERR_ENOMEM;
		return(-1);
	}
	newargv[newargvidx++] = argv[0];
	newargv[argc] = NULL;

	/* Allocate space to indicate which arguments have been used. */
	usedargv = malloc(argc * sizeof(*usedargv));
	if (usedargv == NULL) {
		lc_errfile = local_lc_errfile;
		lc_errline = local_lc_errline;
		lc_erroptname = NULL;
		lc_errno = LC_ERR_ENOMEM;
		free(newargv);
		return(-1);
	}
	for (cmdargidx = 0; cmdargidx < argc; cmdargidx++) {
		usedargv[cmdargidx] = 0;
	}
731
732
733
734
735
736
737
738
739

740
741
742
743
744
745
746
					cmdoptarg = NULL;
				} else {
					cmdargidx++;
					if (cmdargidx >= argc) {
						fprintf(stderr, "Argument required.\n");
						lc_errfile = local_lc_errfile;
						lc_errline = local_lc_errline;
						lc_errno = LC_ERR_BADFORMAT;
						lc_erroptname = strdup(cmdarg);

						free(usedargv);
						free(newargv);
						return(-1);
					}
					cmdoptarg = argv[cmdargidx];
					newargv[newargvidx++] = cmdoptarg;
					usedargv[cmdargidx] = 1;







<

>







733
734
735
736
737
738
739

740
741
742
743
744
745
746
747
748
					cmdoptarg = NULL;
				} else {
					cmdargidx++;
					if (cmdargidx >= argc) {
						fprintf(stderr, "Argument required.\n");
						lc_errfile = local_lc_errfile;
						lc_errline = local_lc_errline;

						lc_erroptname = strdup(cmdarg);
						lc_errno = LC_ERR_BADFORMAT;
						free(usedargv);
						free(newargv);
						return(-1);
					}
					cmdoptarg = argv[cmdargidx];
					newargv[newargvidx++] = cmdoptarg;
					usedargv[cmdargidx] = 1;
757
758
759
760
761
762
763

764
765
766
767
768
769
770
				break;
			}

			if (handler == NULL) {
				fprintf(stderr, "Unknown option: --%s\n", cmdarg);
				lc_errfile = local_lc_errfile;
				lc_errline = local_lc_errline;

				lc_errno = LC_ERR_INVCMD;
				free(usedargv);
				free(newargv);
				return(-1);
			}
		} else {
			for (; *cmdarg != '\0'; cmdarg++) {







>







759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
				break;
			}

			if (handler == NULL) {
				fprintf(stderr, "Unknown option: --%s\n", cmdarg);
				lc_errfile = local_lc_errfile;
				lc_errline = local_lc_errline;
				lc_erroptname = strdup(cmdarg);
				lc_errno = LC_ERR_INVCMD;
				free(usedargv);
				free(newargv);
				return(-1);
			}
		} else {
			for (; *cmdarg != '\0'; cmdarg++) {
787
788
789
790
791
792
793

794
795
796
797
798
799
800
801
802
803
804
805
806
807

808
809
810
811
812
813
814
815
816
817



818
819
820
821
822
823
824
						cmdoptarg = NULL;
					} else {
						cmdargidx++;
						if (cmdargidx >= argc) {
							fprintf(stderr, "Argument required.\n");
							lc_errfile = local_lc_errfile;
							lc_errline = local_lc_errline;

							lc_errno = LC_ERR_BADFORMAT;
							free(usedargv);
							free(newargv);
							return(-1);
						}
						cmdoptarg = argv[cmdargidx];
						newargv[newargvidx++] = cmdoptarg;
						usedargv[cmdargidx] = 1;
					}

					chkretval = lc_handle(handler, handler->var, NULL, cmdoptarg, LC_FLAGS_CMDLINE);
					if (chkretval < 0) {
						lc_errfile = local_lc_errfile;
						lc_errline = local_lc_errline;

						retval = -1;
					}

					break;
				}

				if (handler == NULL) {
					fprintf(stderr, "Unknown option: -%c\n", ch);
					lc_errfile = local_lc_errfile;
					lc_errline = local_lc_errline;



					lc_errno = LC_ERR_INVCMD;
					free(usedargv);
					free(newargv);
					return(-1);
				}
			}
		}







>














>










>
>
>







790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
						cmdoptarg = NULL;
					} else {
						cmdargidx++;
						if (cmdargidx >= argc) {
							fprintf(stderr, "Argument required.\n");
							lc_errfile = local_lc_errfile;
							lc_errline = local_lc_errline;
							lc_erroptname = strdup(cmdarg);
							lc_errno = LC_ERR_BADFORMAT;
							free(usedargv);
							free(newargv);
							return(-1);
						}
						cmdoptarg = argv[cmdargidx];
						newargv[newargvidx++] = cmdoptarg;
						usedargv[cmdargidx] = 1;
					}

					chkretval = lc_handle(handler, handler->var, NULL, cmdoptarg, LC_FLAGS_CMDLINE);
					if (chkretval < 0) {
						lc_errfile = local_lc_errfile;
						lc_errline = local_lc_errline;
						lc_erroptname = strdup(cmdarg);
						retval = -1;
					}

					break;
				}

				if (handler == NULL) {
					fprintf(stderr, "Unknown option: -%c\n", ch);
					lc_errfile = local_lc_errfile;
					lc_errline = local_lc_errline;
					lc_erroptname = malloc(2);
					lc_erroptname[0] = ch;
					lc_erroptname[1] = '\0';
					lc_errno = LC_ERR_INVCMD;
					free(usedargv);
					free(newargv);
					return(-1);
				}
			}
		}
884
885
886
887
888
889
890

891
892
893
894
895
896
897
		if (value == NULL &&
		    handler->type != LC_VAR_NONE &&
		    handler->type != LC_VAR_BOOL_BY_EXISTANCE &&
		    handler->type != LC_VAR_SECTION &&
		    handler->type != LC_VAR_SECTIONSTART &&
		    handler->type != LC_VAR_SECTIONEND) {
			lc_errno = LC_ERR_BADFORMAT;

			break;
		}

		return(lc_handle(handler, var, varargs, value, flags));
	}

	return(-1);







>







892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
		if (value == NULL &&
		    handler->type != LC_VAR_NONE &&
		    handler->type != LC_VAR_BOOL_BY_EXISTANCE &&
		    handler->type != LC_VAR_SECTION &&
		    handler->type != LC_VAR_SECTIONSTART &&
		    handler->type != LC_VAR_SECTIONEND) {
			lc_errno = LC_ERR_BADFORMAT;
			lc_erroptname = NULL;
			break;
		}

		return(lc_handle(handler, var, varargs, value, flags));
	}

	return(-1);
970
971
972
973
974
975
976

977
978
979
980
981
982
983
			break;
		case LC_CONF_XML:
			chkretval = lc_process_conf_xml(appname, pathname);
			break;
		default:
			chkretval = -1;
			lc_errno = LC_ERR_INVDATA;

			break;
	}

	return(chkretval);
}

static int lc_process_files(const char *appname, lc_conf_type_t type, const char *extraconfig) {







>







979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
			break;
		case LC_CONF_XML:
			chkretval = lc_process_conf_xml(appname, pathname);
			break;
		default:
			chkretval = -1;
			lc_errno = LC_ERR_INVDATA;
			lc_erroptname = NULL;
			break;
	}

	return(chkretval);
}

static int lc_process_files(const char *appname, lc_conf_type_t type, const char *extraconfig) {
1063
1064
1065
1066
1067
1068
1069





1070
1071
1072
1073
1074
1075
1076
	}

	if (lc_err_usererrmsg) {
		free((char *) lc_err_usererrmsg);

		lc_err_usererrmsg = NULL;
	}






	varhandlers = NULL;

	return;
}

int lc_process(int argc, char **argv, const char *appname, lc_conf_type_t type, const char *extra) {







>
>
>
>
>







1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
	}

	if (lc_err_usererrmsg) {
		free((char *) lc_err_usererrmsg);

		lc_err_usererrmsg = NULL;
	}

	if (lc_erroptname) {
		free(lc_erroptname);
		lc_erroptname = NULL;
	}

	varhandlers = NULL;

	return;
}

int lc_process(int argc, char **argv, const char *appname, lc_conf_type_t type, const char *extra) {