Show
Ignore:
Timestamp:
03/23/08 23:49:06 (9 months ago)
Author:
karpet
Message:

write header

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • libswish3/trunk/src/swish_header.c

    r2046 r2097  
    2020/* check a swish3 header file for correct syntax */ 
    2121 
     22#include <ctype.h> 
    2223#include <sys/param.h> 
    2324#include <stdio.h> 
     
    2728#include <locale.h> 
    2829#include <err.h> 
     30#include <getopt.h> 
    2931 
    3032#include "libswish3.h" 
     33 
     34extern int SWISH_DEBUG; 
     35 
     36static struct option longopts[] = 
     37{ 
     38    {"debug",           required_argument,  0, 'd'}, 
     39    {"help",            no_argument,        0, 'h'}, 
     40    {0, 0, 0, 0} 
     41}; 
     42 
     43int  
     44usage() 
     45{ 
     46 
     47    char * descr = "swish_header reads and writes swish3 header/config files\n"; 
     48    printf("swish_header [opts] file\n"); 
     49    printf("opts:\n --debug [lvl]\n --help\n"); 
     50    printf("\n%s\n", descr); 
     51    exit(0); 
     52} 
    3153 
    3254 
     
    3557{ 
    3658#ifdef LIBXML_READER_ENABLED 
    37     int i; 
    38     swish_Config *config; 
     59    int i, ch; 
     60    int             option_index; 
     61    extern char    *optarg; 
     62    extern int      optind; 
     63    swish_Config   *config; 
     64     
     65    option_index = 0; 
    3966     
    4067    swish_init();     
    4168 
    42     for (i=1; i < argc; i++) { 
     69    while ((ch = getopt_long(argc, argv, "d:h", longopts, &option_index)) != -1) 
     70    { 
     71        switch (ch) 
     72        { 
     73        case 0:    /* If this option set a flag, do nothing else now. */ 
     74            if (longopts[option_index].flag != 0) 
     75                break; 
     76            printf("option %s", longopts[option_index].name); 
     77            if (optarg) 
     78                printf(" with arg %s", optarg); 
     79            printf("\n"); 
     80            break;             
     81 
     82        case 'd': 
     83            printf("turning on debug mode: %s\n", optarg); 
     84 
     85            if (!isdigit(optarg[0])) 
     86                err(1, "-d option requires a positive integer as argument\n"); 
     87 
     88            SWISH_DEBUG = (int) strtol(optarg, (char **) NULL, 10); 
     89            break; 
     90 
     91        case '?': 
     92        case 'h': 
     93        default: 
     94            usage(); 
     95 
     96        } 
     97 
     98    } 
     99     
     100    i = optind; 
     101 
     102    for (; i < argc; i++) { 
    43103        printf("config file %s\n", argv[i]); 
    44         config = swish_read_header( (char*)argv[i] ); 
    45         swish_debug_config(config); 
     104        config = swish_init_config(); 
     105        if (SWISH_DEBUG & SWISH_DEBUG_CONFIG) { 
     106            SWISH_DEBUG_MSG("init_config"); 
     107        } 
     108        swish_config_set_default(config); 
     109        if (SWISH_DEBUG & SWISH_DEBUG_CONFIG) { 
     110            SWISH_DEBUG_MSG("set default"); 
     111        } 
     112        if (!swish_merge_config_with_header( (char*)argv[i], config )) { 
     113            SWISH_CROAK("failed to merge header %s with defaulf config", argv[i]); 
     114        }                 
     115        swish_write_header("swish_header.xml", config); 
     116        if (SWISH_DEBUG & SWISH_DEBUG_CONFIG) { 
     117            SWISH_DEBUG_MSG("header written"); 
     118        } 
    46119        swish_free_config(config); 
    47120    }