Ejemplo n.º 1
0
int main(int argc, char **argv){
	int im_exit = 0;
	FILE *IN;
	int file_open = 0;
	OPT option;
	InitOption(&option);
	GetOption(&option,argc-1,argv+1);
	if(option.help == 1){
		PrintHelp();
		im_exit++;
	}
	if(option.check == 1){
		PrintOption(option);
		im_exit++;
	}
	if(im_exit > 0){
		exit(0);
	}
	if(strlen(option.file) > 0){
		IN = fopen(option.file,"r");
		file_open++;
	}else{
		IN = stdin;
	}

	prnit_ngram2int(IN,option);
	
	if(file_open > 0){
		fclose(IN);
	}
	return(0);
}
Ejemplo n.º 2
0
int main(int argc, char **argv){
	//def and init
	OPT option;
	int im_ext = 0;
	FILE *IN;
	int file_open = 0;
	InitOption(&option);

	//opt analysis
	GetOption(argc-1,argv+1,&option);
	if(option.check > 0){
		PrintOption(option);
		im_ext++;
	}
	if(option.help > 0){
		help();
		im_ext++;
	}
	if(im_ext > 0){
		exit(0);
	}
	if(strlen(option.file) > 0){
		if((IN = fopen(option.file,"rw")) == NULL){perror("fopen()\n"); exit(0);}
		file_open = 1;
	}else{
		IN = stdin;
	}

	//core func
	data_read_print_ngram_from_fp(IN,option);

	//file closer
	if(file_open > 1){
		fclose(IN);
	}
	return(0);
}
Ejemplo n.º 3
0
Archivo: zsh.cpp Proyecto: 0xheart0/vlc
static void ParseOption(const module_config_t *item)
{
    std::string excl, args;
    std::string list;
    std::pair<mcmap::iterator, mcmap::iterator> range;
    std::pair<mumap::iterator, mumap::iterator> range_mod;

    if (item->b_removed)
        return;

    switch(item->i_type)
    {
    case CONFIG_ITEM_MODULE:
        range_mod = capabilities.equal_range(item->psz_type);
        args = "(" + (*range_mod.first).second;
        while (range_mod.first++ != range_mod.second)
            args += " " + range_mod.first->second;
        args += ")";
    break;

    case CONFIG_ITEM_MODULE_CAT:
        range = categories.equal_range(item->min.i);
        args = "(" + (*range.first).second;
        while (range.first++ != range.second)
            args += " " + range.first->second;
        args += ")";
    break;

    case CONFIG_ITEM_MODULE_LIST_CAT:
        range = categories.equal_range(item->min.i);
        args = std::string("_values -s , ") + item->psz_name;
        while (range.first != range.second)
            args += " '*" + range.first++->second + "'";
    break;

    case CONFIG_ITEM_LOADFILE:
    case CONFIG_ITEM_SAVEFILE:
        args = "_files";
        break;
    case CONFIG_ITEM_DIRECTORY:
        args = "_files -/";
        break;

    case CONFIG_ITEM_STRING:
    case CONFIG_ITEM_INTEGER:
        if (item->list_count == 0)
            break;

        for (int i = 0; i < item->list_count; i++) {
            std::string val;
            if (item->list_text) {
                const char *text = item->list_text[i];
                if (item->i_type == CONFIG_ITEM_INTEGER) {
                    std::stringstream s;
                    s << item->list.i[i];
                    val = s.str() + "\\:\\\"" + text;
                } else {
                    if (!item->list.psz[i] || !text)
                        continue;
                    val = item->list.psz[i] + std::string("\\:\\\"") + text;
                }
            } else
                val = std::string("\\\"") + item->list.psz[i];

            list = val + "\\\" " + list;
        }

        if (item->list_text)
            args = std::string("((") + list + "))";
        else
            args = std::string("(") + list + ")";

        break;

    case CONFIG_ITEM_BOOL:
        excl = std::string("--no") + item->psz_name + " --no-" + item->psz_name;
        PrintOption(item, item->psz_name,                       excl, args);

        excl = std::string("--no") + item->psz_name + " --"    + item->psz_name;
        PrintOption(item, std::string("no-") + item->psz_name,  excl, args);

        excl = std::string("--no-")+ item->psz_name + " --"  + item->psz_name;
        PrintOption(item, std::string("no") + item->psz_name,   excl, args);
        return;

    case CONFIG_ITEM_KEY:
    case CONFIG_SECTION:
    case CONFIG_ITEM_FLOAT:
    default:
        break;
    }

    PrintOption(item, item->psz_name, "", args);
}
Ejemplo n.º 4
0
int main(int argc,                     /* number of arguments */
       char *argv[])                     /* list of arguments */
{
       ATTRIBUTES opt;
       int c;
        CSF_VS valueScale = VS_UNDEFINED;
       enum MODE { CLONE, EDIT, COPY, PRINT, SET } mode = CLONE;

       /* install application */
       if(InstallArgs(argc, argv, "(ecps)dR#C#i#P*x$y$l$a$(BLNOSDV)", 
          "mapattr", __DATE__))
              goto failure;
         OptNotSetAttr(&opt);

       while((c = GetOpt()) != 0)
       {
        switch(c)
        {
         case 'd': printDataType = TRUE; mode = PRINT; break;
         case 'e': mode = EDIT; break;
         case 'c': mode = COPY; break;
         case 'p': mode = PRINT; break;
         case 's': mode = SET; break;
         case 'R': 
            if (*((const int *)OptArg) <= 0)
            { Error("-R number of rows must be greater than 0 (not '%d)",
                     *((const int *)OptArg));
              goto failure;
            }
            opt.nrRows = *((const int *)OptArg); 
            break;
         case 'C': 
            if (*((const int *)OptArg) <= 0)
            { Error("-R number of columns must be greater than 0 (not '%d)",
                     *((const int *)OptArg));
              goto failure;
            }
            opt.nrCols = *((const int *)OptArg); 
            break;
         case 'i': 
            if (*((const int *)OptArg) < 0)
            { Error("-i file id must be >= 0 (not '%d)",
                     *((const int *)OptArg));
              goto failure;
            }
            opt.gisFileId = *((const int *)OptArg); 
            break;
         case 'P':
             if (StrEq("yt2b", (const char *)OptArg))
             {
                    opt.projection = PT_YINCT2B;
                    break;
             }
             if (StrEq("yb2t", (const char *)OptArg))
             {
                    opt.projection = PT_YDECT2B;
                    break;
             }
            Error("-P unknown projection '%s'",(const char *)OptArg);
            goto failure;
         case 'x': opt.xUL = *((const double *)OptArg); break;
         case 'y': opt.yUL = *((const double *)OptArg); break;
         case 'l': 
            if (*((const double *)OptArg) <= 0)
            { Error("-l cell length must be greater than 0 (not '%g)",
                     *((const double *)OptArg));
              goto failure;
            }
            opt.cellSize = *((const double *)OptArg); break;
         case 'a': 
            if ( (*((const double *)OptArg) < -90 )
                || (*((const double *)OptArg) > 90 ) )
            { Error("-a angle must be between -90 and 90 (not '%g)",
                     *((const double *)OptArg));
              goto failure;
            }
            opt.angle = *((const double *)OptArg); break;
#         include "case_vs.h"
       } /* eoswitch */
       } /* eowhile */
       if (valueScale != VS_UNDEFINED)
       {
         opt.valueScale = valueScale;
               opt.cellRepr = AppDefaultCellRepr(valueScale);
       }

       if ( (argv = ArgArguments(&argc)) == NULL)
              goto failure;

       if (AppArgCountCheck(argc,2,-1,USAGE))
              goto failure;

       switch(mode) {
        case PRINT: 
                    if (PrintOption((const char **)argv+1,argc-1))
                           goto failure;
                    break;
        case CLONE: if (argc != 2)
                    {
                     Error("Too many arguments, only one map allowed");
                     goto failure;
                    }
                    if (CloneOption(argv[1]))
                           goto failure;
                    break;
        case EDIT:  if (argc != 2)
                    {
                     Error("-e: Too many arguments, only one map allowed");
                     goto failure;
                    }
                    if (EditOption(argv[1]))
                           goto failure;
                    break;
       case COPY:
                    if (argc <= 2)
                    {
                     Error("-c: requires more than one map");
                     goto failure;
                    }
                    if (CopyOption((const char **)argv+1,argc-1))
                           goto failure;
                    break;
        case SET:
                    if (SetOption((const char **)argv+1,argc-1,&opt))
                           goto failure;
                    break;
       }

       AppEnd();
       exit(0);
       return 0;

failure:
       AppEnd();
       exit(1);
       return 1;
} /* main */