示例#1
0
文件: secho.c 项目: Orc/secho
/* read arguments from a file.
 */
void
filetokens(FILE *in, FILE *out)
{
    char c;
    char mydelim = zero ? 0 : (delim ? delim : '\n');

    do { 
	S(arg) = 0;

	while ( (c = getc(in)) != EOF && c != mydelim )
	    EXPAND(arg) = c;
	if ( (c == EOF) && (S(arg) == 0) )
	    break;

	EXPAND(arg) = 0;
	S(arg)--;

	if ( !match_re(T(arg)) )
	    continue;
	
	counter++;
	if ( cmd )
	    docommand(out);
	else if ( out )
	    printarg(out);
    } while ( c != EOF );
}
示例#2
0
int queryOperation_test()
{
/* Internal unit test */
    //Test match_re()
    char *str="123456";
    char *re="%345%";
    int rc;
    int fail=0;
    rc=match_re(str,re);
    if (rc==0) {
        printf("match_re() failed test %s, rc=%d\n",re,rc);
        fail=1;
    }
    re="%999%";
    rc=match_re(str,re);
    if (rc!=0) {
        printf("match_re() failed test %s, rc=%d\n",re,rc);
        fail=1;
    }
    re="%456";
    rc=match_re(str,re);
    if (rc==0) {
        printf("match_re() failed test %s, rc=%d\n",re,rc);
        fail=1;
    }
    re="123%";
    rc=match_re(str,re);
    if (rc==0) {
        printf("match_re() failed test %s, rc=%d\n",re,rc);
        fail=1;
    }
    re="123456";
    rc=match_re(str,re);
    if (rc==0) {
        printf("match_re() failed test %s, rc=%d\n",re,rc);
        fail=1;
    }

    return fail;
}
示例#3
0
static int _notLikeEvaluate(QLOperation *op, QLPropertySource* source) 
{
   char *sov,*ov;
   QLOpd type;

   CMPIValue v=getPropValue(op->lhod, source, &type);
   sov = v.chars;
   type=op->rhod->type;
   if (type==QL_PropertyName) 
      ov=getPropValue(op->rhod, source, &type).chars;
   else 
       ov=op->rhod->charsVal;
   if (type==QL_Chars && sov && ov)
   {
       int rc = match_re(sov, ov);
       return (rc == 0);
   }
   return 0;
}
示例#4
0
文件: secho.c 项目: Orc/secho
/* read arguments off the command line
 */
void
cmdtokens(char *in, FILE *out)
{
    do {
	S(arg) = 0;

	while ( *in && (*in != delim) )
	    EXPAND(arg) = *in++;

	if ( *in ) ++in;

	EXPAND(arg) = 0;
	S(arg)--;

	if ( !match_re(T(arg)) )
	    continue;
	
	counter++;
	if ( cmd )
	    docommand(out);
	else if ( out )
	    printarg(out);
    } while ( *in );
}
string comfy_keyword_public(string name, string source)
{
    struct slre_cap groups[2];
    string match_start;
    int start = 0;
    int bytes_read = 0;
    int source_len = strlen(source);

    string target;
    asprintf(&target, "");
    bool found = false;
    string end_of_match;

    while (0 < (bytes_read = match_re(source, start, groups, &match_start)))
    {
        found = true;
        const string docstr  = (const string) groups[0].ptr;
        int docstr_len = groups[0].len;
        const string mhead   = (const string) groups[1].ptr;
        int mhead_len  = groups[1].len;

        //string match_start = docstr ? docstr : mhead;
        string source_start = source + start;
        target = append_to(target, source_start, match_start - source_start);

        if (docstr)
        {
            string pubdoc = make_public_string(docstr, docstr_len);
            target = append_str_to(target, pubdoc);
        }

        string pub_mhead = make_public_string(mhead, mhead_len);
        target = append_str_to(target, "\n");

        target = append_str_to(target, pub_mhead);
        target = append_str_to(target, ";\n");
        target = append_to(target, mhead, mhead_len);

        end_of_match = mhead + mhead_len;
        start = end_of_match - source;

        /*
        int size_matched =  groups[1].ptr - source + groups[1].len;

        remove_whitespace(&groups[0]);
        remove_whitespace(&groups[1]);
        if (0 >= groups[0].len || 0 >= groups[1].len){
            return NULL;
        }

        string start_str = source + start;

        string append_target;
        asprintf(&append_target, "%s%.*s", target,
                (int)(groups[0].ptr - start_str),  start_str);

        string to_header;
        string to_source;

        asprintf(&to_header, "§%.*s\n%.*s;",
                groups[0].len, groups[0].ptr,
                groups[1].len, groups[1].ptr);
        string masked = string_replace_all_in(to_header, "\n", "\n§");

        asprintf(&to_source, "%s%s\n%.*s",
                append_target,
                masked, groups[1].len, groups[1].ptr);



        free(masked);
        free(append_target);
        free(to_header);

        free(target);
        target = to_source;

        end_of_match = source + start + bytes_read - 1;
*/
    }

    if (found){
        string append_tail;
        asprintf(&append_tail, "%s%s", target, end_of_match);
        free(target);
        return append_tail;
    } else {
        return NULL;
    }
}