Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8020235
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T21:37:50+00:00 2026-06-04T21:37:50+00:00

How can I, in a c program, perform a glob by using the function

  • 0

How can I, in a c program, perform a glob by using the function provided by the z shell?

I have created a README of my explorations so far. It is for use in an open source library.

https://bitbucket.org/sentimental/zsh_source_experimentation/src/master/README

I copy it here:


Start

Lets get the sources

apt-get source zsh
apt-get source zsh-dev

I’ve discovered by using ldd that zsh does not produce any library files::

#ldd /bin/zsh4

        linux-gate.so.1 =>  (0xb7775000)
        libcap.so.2 => /lib/i386-linux-gnu/libcap.so.2 (0xb7751000)
        libdl.so.2 => /lib/i386-linux-gnu/libdl.so.2 (0xb774c000)
        libtinfo.so.5 => /lib/i386-linux-gnu/libtinfo.so.5 (0xb772c000)
        libm.so.6 => /lib/i386-linux-gnu/libm.so.6 (0xb7700000)
        libc.so.6 => /lib/i386-linux-gnu/libc.so.6 (0xb755b000)

I think I will have to use the source files directly.

Lets locate the files containing references to extended globbling
(I’m using zsh as my shell).::

grep -ir EXTENDEDGLOB . |  egrep "\.(c|h):"  | cut -d: -f1 | sort -u

./README
./zsh-4.3.17/Etc/ChangeLog-3.0
./zsh-4.3.17/Src/glob.c
./zsh-4.3.17/Src/Modules/zutil.c
./zsh-4.3.17/Src/options.c
./zsh-4.3.17/Src/pattern.c
./zsh-4.3.17/Src/utils.c
./zsh-4.3.17/Src/Zle/complist.c
./zsh-4.3.17/Src/Zle/zle_tricky.c
./zsh-4.3.17/Src/zsh.h

Lets consider a couple of those files

zsh.h

In here EXTENDEDGLOB is defined as part of an anonymous enum

There are publications

here
http://publications.gbdirect.co.uk/c_book/chapter6/enums.html

and here
http://bytes.com/topic/c/answers/63891-enum-within-function-standard

detailing the use of enum in c

An example of its use is probably the method arguments for the function
…………….

 static int
    bin_zregexparse(char *nam, char **args, Options ops, UNUSED(int func))

Found in the file
……………..

./zsh-4.3.17/Src/Modules/zutil.c

Lets see what’s calling that function. Hmm only one call. The only reference to that call is in that file.

grep -r  bin_zregexparse . |  egrep "\.(c|h):"  | cut -d: -f1 | sort -u

./zsh-4.3.17/Src/Modules/zutil.c

Hmm…. How does it work if nothing calls this function?

Ok lets see if there is some conditional configuration that sets up or aliases this code somehow?

 grep -i regex ./**/conf*

/zsh-4.3.17/config.h.in :/* Define to 1 if you have the `regexec' function. */
./zsh-4.3.17/config.h.in :#undef HAVE_REGEXEC
./zsh-4.3.17/config.h.in :/* Define to 1 if you have the `regexec' function. */
./zsh-4.3.17/config.h.in :#undef HAVE_REGEXEC
./zsh-4.3.17/configure :       regcomp regexecc regerror regfree \
./zsh-4.3.17/configure :       regcomp regexec regexecerror regfree \
./zsh-4.3.17/configure.ac :       regcomp regexec regerrorror regfree \

Lets investigate these files.

 config.h.in

Doesn’t seem to exist, perhaps it is generated?

There seems to be a block in

 configure


 8148 for ac_func in strftime strptime mktime timelocal \     
 8149          difftime gettimeofday clock_gettime \          
 8150          select poll \                                  
 8151          readlink faccessx fchdir ftruncate \           

 etc etc etc ..

 8178          htons ntohs \                                   
 8179          regcomp regexec regerror regfree \              
 8180          gdbm_open getxattr \                            
 8181          realpath canonicalize_file_name \               
 8182          symlink getcwd                                  
 8183 do :                                                     
 8184   as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh` 
 8185 ac_fn_c_check_func "$LINENO" "$ac_func" "$as_ac_var"     
 8186 if eval test \"x\$"$as_ac_var"\" = x"yes"; then :        
 8187   cat >>confdefs.h <<_ACEOF                              
 8188 #define `$as_echo "HAVE_$ac_func" | $as_tr_cpp` 1        
 8189 _ACEOF                                                   
 8190                                                          
 8191 fi                                                       
 8192 done                                                     

}}}

I’ve no idea what that is doing. TODO: Investigate!

In

  ./zsh-4.3.17/configure.ac 

  1167 dnl ---------------
  1168 dnl CHECK FUNCTIONS
  1169 dnl ---------------
  1170                                                                                                                                                                                  |     rglobdata.gd_gf_noglobdot
  1171 dnl need to integrate this function
  1172 dnl AC_FUNC_STRFTIME
  1173                                                                                                                                                                                  |     rglobdata.gd_gf_listtypes
  1174 AC_CHECK_FUNCS(strftime strptime mktime timelocal \
  1175          difftime gettimeofday clock_gettime \
  1176          select poll \

  etc etc etc 


  1205          regcomp regexec regerror regfree \                                 
  1206          gdbm_open getxattr \                                               
  1207          realpath canonicalize_file_name \                                  
  1208          symlink getcwd)                                                    
  1209 AC_FUNC_STRCOLL

Not really sure at this stage how I can do this, consider that I perhaps want to unit-test that function, how might I do so?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T21:37:52+00:00Added an answer on June 4, 2026 at 9:37 pm

    The function bin_zregexparse is the implementation of the zregexparse builtin provided by the zsh/zutil module. It is used below its definition in zutil.c:

    static struct builtin bintab[] = {
        …
        BUILTIN("zregexparse", 0, bin_zregexparse, 3, -1, 0, "c", NULL),
        …
    };
    

    zregexparse is intended to be used in the implementation of _regex_arguments. This isn’t the most promising entry point.

    If you want to implement zsh’s globbing features, you’ll have to pull in almost all of the zsh code into your program, since glob patterns can contain arbitrary embedded code. You can exclude the line editor during build, but that’s about it.

    I would recommend using a separate zsh binary and feeding it requests through a pair of pipes.

    setopt extended_glob null_glob
    print -Nr -- **/*(.Om+my_predicate) ''
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have written a program using Python and OpenCV where I perform operations on
I have a program where the user can press a key to perform an
I have created a C# program that can dial a phone. Now what I
I have program, that must interact with a console program before my program can
I created a SQLite database on Android device. The program can read/write to database
I've got a table recording views of programs. Each program can have two different
I have my program that can draw rectangles. I have two problems I can't
Using my c++ program how can I find out what group the current user
I have a program that can send text to any other program for further
Possible Duplicate: Convention question: When do you use a Getter/Setter function rather than using

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.