+static void
+parse_options(int argc, char *argv[])
+{
+ int i;
+ int got_file = FALSE;
+ int no_opts = FALSE;
+
+ filename = NULL;
+
+ for(i=1;i<argc;i++) {
+ if(no_opts || argv[i][0]!='-') {
+ /*must be a file*/
+ if(got_file) {
+ fprintf(stderr,"Specify only one file!\n");
+ print_help();
+ exit(1);
+ }
+ filename = argv[i];
+ got_file = TRUE;
+ } else if(strcmp(argv[i],"--help")==0) {
+ print_help();
+ exit(0);
+ } else if(strcmp(argv[i],"--version")==0) {
+ fprintf(stderr,"Gob version %s\n",VERSION);
+ exit(0);
+ } else if(strcmp(argv[i],"--exit-on-warn")==0) {
+ exit_on_warn = TRUE;
+ } else if(strcmp(argv[i],"--no-exit-on-warn")==0) {
+ exit_on_warn = FALSE;
+ } else if(strcmp(argv[i],"--for-cpp")==0) {
+ for_cpp = TRUE;
+ } else if(strcmp(argv[i],"--no-touch-headers")==0) {
+ no_touch_headers = TRUE;
+ } else if(strcmp(argv[i],"--always-private-header")==0) {
+ no_private_header = FALSE;
+ always_private_header = TRUE;
+ } else if(strcmp(argv[i],"--no-private-header")==0) {
+ always_private_header = FALSE;
+ no_private_header = TRUE;
+ } else if(strcmp(argv[i],"--no-gnu")==0) {
+ no_gnu = TRUE;
+ } else if(strcmp(argv[i],"--no-extern-c")==0) {
+ no_extern_c = TRUE;
+ } else if(strcmp(argv[i],"--")==0) {
+ /*further arguments are files*/
+ no_opts = TRUE;
+ } else if(strncmp(argv[i],"--",2)==0) {
+ /*unknown long option*/
+ fprintf(stderr,"Unknown option '%s'!\n",argv[i]);
+ print_help();
+ exit(1);
+ } else {
+ /*by now we know we have a string starting with
+ - which is a short option string*/
+ char *p = argv[i]+1;
+ for(p=argv[i]+1;*p;p++) {
+ switch(*p) {
+ case 'w':
+ exit_on_warn=TRUE;
+ break;
+ case 'h':
+ case '?':
+ print_help();
+ exit(0);
+ default:
+ fprintf(stderr,
+ "Unknown option '%c'!\n",*p);
+ print_help();
+ exit(1);
+ }
+ }
+ }
+ }
+}
+
+/* this is a somewhat ugly hack, but it appears to work */
+static void
+compare_and_move_header(void)
+{
+ char *hfnew = g_strconcat("#gob#",filebase,".h#gob#",NULL);
+ char *hf = g_strconcat(filebase,".h",NULL);
+ struct stat s;
+ if(stat(hf,&s)==0) {
+ char *s;
+ s = g_strdup_printf("cmp '%s' '%s' > /dev/null",hf,hfnew);
+ if(system(s)==0) {
+ if(unlink(hfnew)!=0)
+ print_error(FALSE,"Can't remove new header file",0);
+ g_free(hfnew);
+ g_free(hf);
+ g_free(s);
+ return;
+ }
+ g_free(s);
+ if(unlink(hf)!=0)
+ print_error(FALSE,"Can't remove old header file",0);
+ }
+ if(rename(hfnew,hf)!=0)
+ print_error(FALSE,"Can't rename new header file",0);
+ g_free(hfnew);
+ g_free(hf);
+}