int main (int argc, char const *argv []) { static char const *optv [] = { "h", "findspec [ findspec [ ... ] ] [> stdout]", "demonstrate pathname expansion function, findpath() ", "h\thelp summary ", NULL }; struct _find_ find; // signed argn; signed c; optind = 1; opterr = 1; while ((c = getoptv (argc, argv, optv)) != -1) { switch (c) { case ':': exit (1); case '?': exit (1); default: break; } } argc -= optind; argv += optind; while ((argc-- > 0) && (*argv != (char *)(0))) { makefind (&find, *argv++, FIND_M_NORMAL); showfind (&find, stdout); } exit (0); }
int main (int argc, char const * argv []) { extern FIND find; static char const * optv [] = { "copy remote files to local folder", "folder findspec [findspec] [...]", "o:qrv", "q\tquiet (don't report failures)", "r\trecursive search", "v\tverbose (report successes)", (char const *) (0) }; FIND home; flag_t flags = (flag_t) (0); signed c; while (~ (c = getoptv (argc, argv, optv))) { switch (c) { case 'r': _setbits (find.flagword, FIND_B_RECURSE); break; case 'q': _clrbits (flags, IMPORT_SILENCE); break; case 'v': _setbits (flags, IMPORT_VERBOSE); break; default: break; } } argc -= optind; argv += optind; if (_allclr (find.flagword, (FIND_B_LNK | FIND_B_REG))) { _setbits (find.flagword, (FIND_B_LNK | FIND_B_REG)); } if (argc) { strcpy (home.pathname, * argv); if (lstat (home.pathname, & home.statinfo)) { error (1, errno, FILE_CANTSTAT, * argv); } if (! S_ISDIR (home.statinfo.st_mode)) { error (1, EINVAL, "%s is not a folder", * argv); } argc--; argv++; } while ((argc) && (* argv)) { makefind (& find, * argv); findfile (& find, & home, flags); argc--; argv++; } exit (0); }
int main (int argc, char const * argv []) { extern FIND find; static char const * optv [] = { "e:p:x", PUTOPTV_S_FILTER, "insert shell bang path header", "e s\tpathname defined by environement variable s", "p s\tpathname string is s", "x\tmake file executable", (char const *) (0) }; char const * pathname = ""; flag_t flags = (flag_t) (0); size_t length = _LINESIZE; signed c; while (~ (c = getoptv (argc, argv, optv))) { switch (c) { case 'e': if ((pathname = getenv (optarg)) == (char *)(0)) { error (1, errno, "symbol %s not defined", optarg); } break; case 't': if ((pathname = getenv ("CMTOOLS")) == (char *)(0)) { error (1, errno, "symbol CMTOOLS is undefined"); } break; case 'p': pathname = optarg; break; case 'x': _setbits (flags, SHBANG_EXECUTE); break; default: break; } } argc -= optind; argv += optind; if (!argc) { function (& find, length, flags); } while ((argc) && (* argv)) { makefind (& find, * argv); if (vfopen (find.fullname)) { if ((!pathname) || (!* pathname)) { strcpy (find.pathname, pathname); } strcat (find.pathname, PATH_S_EXTENDER); strcat (find.pathname, find.filename); function (& find, length, flags); if (_anyset (flags, SHBANG_EXECUTE)) { if (chmod (find.fullname, 0755)) { error (0, errno, "can't chmod %s", find.fullname); } } } argc--; argv++; } exit (0); }