AnonSec Shell
Server IP : 185.86.78.101  /  Your IP : 216.73.216.124
Web Server : Apache
System : Linux 675867-vds-valikoshka1996.gmhost.pp.ua 5.4.0-150-generic #167-Ubuntu SMP Mon May 15 17:35:05 UTC 2023 x86_64
User : www ( 1000)
PHP Version : 7.4.33
Disable Function : passthru,exec,system,putenv,chroot,chgrp,chown,shell_exec,popen,proc_open,pcntl_exec,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,imap_open,apache_setenv
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF  |  Sudo : ON  |  Pkexec : OFF
Directory :  /usr/share/doc/libonig-dev/examples/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ HOME ]     

Current File : /usr/share/doc/libonig-dev/examples/count.c
/*
 * count.c
 */
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "oniguruma.h"

#define ulen(enc, p) onigenc_str_bytelen_null(enc, (UChar* )p)

static int
test(OnigEncoding enc, OnigMatchParam* mp, char* in_pattern, char* in_str)
{
  int r;
  unsigned char *start, *range, *end;
  regex_t* reg;
  OnigErrorInfo einfo;
  OnigRegion *region;
  UChar* pattern;
  UChar* str;

  pattern = (UChar* )in_pattern;
  str = (UChar* )in_str;

  r = onig_new(&reg, pattern, pattern + ulen(enc, pattern),
               ONIG_OPTION_DEFAULT, enc, ONIG_SYNTAX_DEFAULT, &einfo);
  if (r != ONIG_NORMAL) {
    char s[ONIG_MAX_ERROR_MESSAGE_LEN];
    onig_error_code_to_str((UChar* )s, r, &einfo);
    fprintf(stderr, "COMPILE ERROR: %d: %s\n", r, s);
    return -1;
  }

  region = onig_region_new();

  end   = str + ulen(enc, str);
  start = str;
  range = end;
  r = onig_search_with_param(reg, str, end, start, range, region,
                             ONIG_OPTION_NONE, mp);
  if (r >= 0) {
    int slot;
    OnigValue val;
    char* tag;
    int tag_len;

    fprintf(stdout, "match at %d\n", r);

  show_count:
    if (enc == ONIG_ENCODING_UTF16_BE) {
      tag = "\000x\000\000";
    }
    else if (enc == ONIG_ENCODING_UTF16_LE) {
      tag = "x\000\000\000";
    }
    else {
      tag = "x";
    }
    tag_len = ulen(enc, tag);

    slot = 0;
    r = onig_get_callout_data_by_tag(reg, mp, (UChar* )tag, (UChar* )tag + tag_len,
                                     slot, 0, &val);
    if (r < ONIG_NORMAL) goto err;
    else if (r > ONIG_NORMAL) {
      fprintf(stdout, "COUNT[x]: NO DATA\n");
    }
    else {
      fprintf(stdout, "COUNT[x]: %ld\n", val.l);
    }
  }
  else if (r == ONIG_MISMATCH) {
    fprintf(stdout, "search fail\n");
    goto show_count;
  }
  else { /* error */
    char s[ONIG_MAX_ERROR_MESSAGE_LEN];
  err:
    onig_error_code_to_str((UChar* )s, r);
    fprintf(stdout, "SEARCH ERROR: %d: %s\n", r, s);
  }

  onig_region_free(region, 1 /* 1:free self, 0:free contents only */);
  onig_free(reg);
  return r;
}

extern int main(int argc, char* argv[])
{
  int r;
  OnigMatchParam* mp;
  OnigEncoding encs[3];

  encs[0] = ONIG_ENCODING_UTF8;
  encs[1] = ONIG_ENCODING_UTF16_BE;
  encs[2] = ONIG_ENCODING_UTF16_LE;

  r = onig_initialize(encs, sizeof(encs)/sizeof(encs[0]));
  if (r != ONIG_NORMAL) {
    fprintf(stderr, "FAIL: onig_initialize(): %d\n", r);
    return -1;
  }

  mp = onig_new_match_param();

  test(encs[0], mp, "abc(.(*COUNT[x]))*(*FAIL)", "abcdefg");
  test(encs[0], mp, "abc(.(*COUNT[_any_]))*(.(*COUNT[x]))*d", "abcdefg");
  /* fail count */
  test(encs[0], mp, "abc(.(*COUNT[x]{<}))*f", "abcdefg");
  /* success count */
  test(encs[0], mp, "abc(.(*COUNT[x]{X}))*f", "abcdefg");
  /* passed count */
  test(encs[0], mp, "abc(.(*COUNT[x]))*f", "abcdefg");
  test(encs[0], mp, "a(.(*COUNT[x]))*z", "abcd\nabcdz");
  /* total count */
  test(encs[0], mp, "a(.(*TOTAL_COUNT[x]))*z", "abcd\nabcdz");

  test(encs[1], mp, "\000a\000b\000c\000(\000.\000(\000*\000C\000O\000U\000N\000T\000[\000x\000]\000)\000)\000*\000(\000*\000F\000A\000I\000L\000)\000\000", "\000a\000b\000c\000d\000e\000f\000g\000\000");

  test(encs[2], mp, "a\000b\000c\000(\000.\000(\000*\000C\000O\000U\000N\000T\000[\000x\000]\000)\000)\000*\000(\000*\000F\000A\000I\000L\000)\000\000\000", "a\000b\000c\000d\000e\000f\000g\000\000\000");

  onig_free_match_param(mp);
  onig_end();
  return 0;
}

Anon7 - 2022
AnonSec Team