Guest User

Untitled

a guest
Mar 19th, 2013
96
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include "pcre.h"
  2. #include <stdio.h>
  3. #include <string.h>
  4. #include <sys/stat.h>
  5. #include <errno.h>
  6.  
  7. unsigned int filesize(const char *filename) {
  8.     struct stat sb;
  9.  
  10.     if (stat(filename, &sb)) {
  11.         printf("Stat error: %s\n", strerror(errno));
  12.         return 0;
  13.     }
  14.  
  15.     return sb.st_size;
  16. }
  17.  
  18. int main() {
  19.     char *regexp = "(?s)(?:\\pL+\\n){5000}";
  20.  
  21.     const char *error;
  22.     int erroffset;
  23.  
  24.     pcre *re = pcre_compile(
  25.         regexp,
  26.         PCRE_UTF8,
  27.         &error,
  28.         &erroffset,
  29.         NULL
  30.     );
  31.  
  32.     printf("PCRE version: %s\n", pcre_version());
  33.  
  34.     if (!re) {
  35.         printf("Compile error: %s\n", error);
  36.         return 1;
  37.     }
  38.  
  39.     char *filename = "utf8.txt";
  40.  
  41.     size_t size = filesize(filename);
  42.     char *str = malloc(size + 1);
  43.     FILE *fp = fopen(filename, "r");
  44.  
  45.     fread(str, sizeof(char), size, fp);
  46.     fclose(fp);
  47.  
  48.     int match;
  49.     int offsets[3];
  50.  
  51.     for (int i = 0; i<10; i++) {
  52.         match = pcre_exec(re, NULL, str, size, 0, 0, offsets, 3);
  53.         printf(match == PCRE_ERROR_NOMATCH ? "No!\n" : "Yes!\n");
  54.     }
  55.  
  56.     free(str);
  57.  
  58.    
  59. }
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×