{"id":21970685,"url":"https://github.com/sirwumpus/ioccc-ag","last_synced_at":"2025-04-28T11:24:51.773Z","repository":{"id":98631453,"uuid":"90914428","full_name":"SirWumpus/ioccc-ag","owner":"SirWumpus","description":"Best Utility (grep) - IOCCC 1993 Winner","archived":false,"fork":false,"pushed_at":"2023-06-25T11:21:30.000Z","size":22,"stargazers_count":10,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-28T11:24:46.721Z","etag":null,"topics":["c","grep","ioccc","posix","regular-expressions"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"0bsd","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/SirWumpus.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-05-10T22:40:44.000Z","updated_at":"2025-02-06T04:50:57.000Z","dependencies_parsed_at":"2023-03-07T10:30:30.233Z","dependency_job_id":null,"html_url":"https://github.com/SirWumpus/ioccc-ag","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SirWumpus%2Fioccc-ag","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SirWumpus%2Fioccc-ag/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SirWumpus%2Fioccc-ag/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SirWumpus%2Fioccc-ag/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/SirWumpus","download_url":"https://codeload.github.com/SirWumpus/ioccc-ag/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251303463,"owners_count":21567699,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["c","grep","ioccc","posix","regular-expressions"],"created_at":"2024-11-29T14:41:47.345Z","updated_at":"2025-04-28T11:24:51.762Z","avatar_url":"https://github.com/SirWumpus.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"ag - Anthony's Grep\n------------------\n\n\n## 1. SYNOPSIS\n\n\tag pattern [file...]\n\n\n## 2. DESCRIPTION\n\nThe AG utility shall search input files, selecting lines matching a\npattern.  An input line shall be selected if the pattern, treated as a\nsubset of Extended Regular Expressions as described by POSIX.2\nStandard section 2.8.4, matches any part of the line; a null pattern\nshall match every line.  Each selected input line shall be written to\nthe standard output.\n\nRegular expression matching shall be based on text lines, which are\nseparated by a `\u003cnewline\u003e` character.  A regular expression cannot\ncontain a `\u003cnewline\u003e` and there is no way for a pattern to match a\n`\u003cnewline\u003e` found in the input.\n\n\n## 3. OPTIONS\n\nNone.\n\n\n## 4. OPERANDS\n\n* `pattern`\tSpecify one pattern to be used during the search for\n\t\tinput.  See Extended Regular Exprssions below on what\n\t\tconstitutes a valid pattern.\n\n* `file`\tA pathname of a file to be searched for the pattern.\n\t\tIf no file operands are specified or the file operand\n\t\tis dash (`-`), the standard input shall be used.\n\n\n## 5. EXTERNINAL INFLUENCES\n\n### 5.1. STANDARD INPUT\n\nThe standard input shall be used only if no file operands are\nspecifed.  See Input Files.\n\n\n### 5.2. INPUT FILES\n\nThe input files shall be text files.\n\n\n### 5.3. ENVIRONMENT VARIABLES\n\nNo environment variables are used.\n\n\n### 5.4. ASYNCHRONOUS EVENTS\n\nDefault.\n\n\n## 6. EXTERNAL EFFECTS\n\n### 6.1. STANDARD OUTPUT\n\nFor each selected input line from a file, a single output line shall\nbe written:\n\n\t\"%s:%s\\n\", file, line\n\nStandard input will have the filename dash (`-`).\n\n\n### 6.2. STANDARD ERROR\n\nStandard error is used for diagnostic messages only.\n\n\n### 6.3. OUTPUT FILES\n\nNone.\n\n\n## 7. EXTENDED DESCRIPTION\n\n### 7.1. EXTENDED REGULAR EXPRESSIONS\n\n#### 7.1.1. MATCHING A SINGLE CHARACTER\n\nAn ERE ordinary character, a special character preceded by a\nbackslash, or a period shall match a single character.  A bracket\nexpression shall match a single character.  An ERE matching a single\ncharacter enclosed in parentheses shall match the same as the ERE\nwithout parentheses would have matched.\n\n\n##### 7.1.1.1. ERE ORDINARY CHARACTERS\n\nAn oridinary character is an ERE that matches itself.  An ordinary\ncharacter is any character in the supported character set, except for\nthe ERE special characters listed in 7.1.1.2.  The interpretation of\nan ordinary character preceded by a backslash (`\\`) is the ordinary\ncharacter.\n\n\n##### 7.1.1.2. ERE SPECIAL CHARACTERS\n\nAn ERE special character has special properties in certain contexts.\nOutside of those contexts, or when preceded by a backslash, such a\ncharacter shall be an ERE that matches the special character itself.\nThe extended regular expression special characters and the contexts in\nwhich they have their special meaning are:\n\n`. [ \\ (`\tThe period, left-bracket, backslash, and left-\n\t\tparenthesis are special except when used in a\n\t\tbracket expression.  Outside a bracket\n\t\texpression, a left-parenthesis immediately\n\t\tfollowed by a right-parenthesis will be\n\t\ttreated as a null expression.\n\n`)`\t\tThe right-parenthesis is special when matched\n\t\twith a preceding left-parenthesis, both\n\t\toutside of a bracket expression.\n\n`* ?`\t\tThe asterisk and question-mark are special\n\t\texcept when used in a bracket expression.\n\t\tResults are undefined if this character\n\t\tappears first in an ERE, or immediately\n\t\tfollowing a vertial-line, circumflex, or\n\t\tleft-parenthesis.\n\n`|`\t\tThe vertical-line is special except when used\n\t\tin a bracket expression.  A vertical-line\n\t\tappearing first or last in an ERE or\n\t\timmediately following a vertical-line or\n\t\tleft-parenthesis, or preceding a\n\t\tright-parenthesis, produces a null expression.\n\n`^`\t\tThe circumflex shall be special when used as\n\t\tan anchor or, as the first character of a\n\t\tbracket expression.\n\n`$`\t\tThe dollar-sign shall be special when used as\n\t\tan anchor.\n\n\n##### 7.1.1.3 PERIODS IN ERE\n\nA period (`.`), when used outside of a bracket expression, is an ERE\nthat shall match any character in the supported character set except\nNUL.\n\n#### 7.1.2. ERE BRACKET EXPRESSION\n\nA bracket expression (an expression enclosed in square brackets, []),\nis an ERE that matches a single character contained in the nonempty\nset of characters represented by the bracket expression.\n\nThe following rules and definitions apply to bracket expressions:\n\n1)\tA bracket expression is either a matching list expression or a\n\tnonmatching list expression.  It consists of one or more\n\tcharacters and/or range expressions.  The right-bracket (`]`)\n\tshall lose its special meaning and represent itself in a bracket\n\texpression if it occurs first in the list [after an initial\n\tcircumflex (`^`), if any].  Otherwise, it shall terminate the\n\tbracket expression.  The special characters period (`.`),\n\tasterisk (`*`), left-bracket (`[`), and backslash (`\\`) shall\n\tlose their special meaning within a bracket expression.\n\n2)\tA matching list expression specifies a list that shall match any\n\tone of the expressions represented in the list.  The first\n\tcharacter of the list shall not be the circumflex.  For example,\n\t[abc]  is an ERE that matches any of a, b, or c.\n\n3)\tA nonmatching list expression begins with a circumflex (`^`),\n\tand specifies a list that shall match any character except for\n\tthe expressions represented in the list after the leading\n\tcircumflex.  For example,  `[^abc]`  is an ERE that matches any\n\tcharacter except a, b, or c.  The circumflex shall have this\n\tspecial meaning only when it occurs first in the list,\n\timmediately following the left-bracket.\n\n4)\tA range expression represents the set of characters that fall\n\tbetween two elements in the current collation sequence,\n\tinclusive.  It shall be expressed as the starting point and the\n\tending point separated by a hyphen (`-`).\n\n\tIn the following, all examples assume the collation sequence\n\tspecified for the POSIX Locale (a.k.a ASCII Character Set),\n\tunless another collation sequence is sepecifically defined by\n\tthe hardware.\n\n\tThe starting range point and the ending range point shall be a\n\tcollating element (character).  The ending range point shall\n\tcollate higher than the starting range point; otherwise the\n\texpression shall be treated as invalid.\n\n\tThe interpretation of a range expression where the ending range\n\tpoint is the starting range point of a subsequent range\n\texpression is undefined.\n\n\tThe hyphen character shall be treated as itself if it occurs\n\tfirst (after an initial `^`, if any) or last in the list, or as\n\tan ending range point in a range expression.  As examples, the\n\texpressions  `[-ac]`  and  `[ac-]` are equivalent and match any\n\tof the characters a, c, or -; the expressions  `[^-ac]`  and\n\t`[^ac-]` are equivalent and match ant character except a, c, -;\n\tthe expression  `[%--]`  matches any of the characters between\n\t`%` and `-` inclusive;  the expression  `[--@]`  matches any of\n\tthe characters between `-` and `@` inclusive; and the expression\n\t`[a--@`] is invalid, because the letter `a` follows the symbol\n\t`-` in the POSIX Locale.\n\n\n#### 7.1.3. ERE MATCHING MULTIPLE CHARACTERS\n\nThe following rules shall be used to construct EREs matching multiple\ncharacters from EREs matching a single character:\n\n1)\tA concatenation of EREs shall match the concatenation of the\n\tcharacter sequences matched by each component of the ERE.  A\n\tconcatenation of EREs enclosed in parentheses shall match\n\twhatever the concatenation without parentheses matches.  For\n\texample, both the ERE cd and the ERE (cd) are matched by the\n\tthird and forth character of the string abcdefabcdef.\n\n2)\tWhen an ERE matching a single character, or a concatention of\n\tEREs enclosed in parentheses is followed by the special\n\tcharacter asterisk (`*`), together with that asterisk it shall\n\tmatch what zero or more consecutive occurences of the ERE\n\twould match.  For example, the ERE `b*c` matches the first\n\tcharacter in the string cabbbcde, and the ERE b*cd matches the\n\tthird through seventh characters in the string\n\tcabbbcdebbbbbbcdbc.  And, `[ab]*` and `[ab][ab]` are equivalent\n\twhen matching the string ab.\n\n 3)\tWhen an ERE matching a single character or an ERE enclosed in\n\tparentheses is followed by the special character question-mark\n\t(`?`), together with that question mark it shall match what zero\n\tor one consecutive occurences of the ERE would match.  For\n\texample, the ERE `b?c` matches the second character in the\n\tstring acabbbcde.\n\nThe behaviour of multiple adjacent duplication symbols (*, ?) produces\nundefined results.\n\n\n#### 7.1.4. ERE ALTERATION\n\nTwo EREs separated by the special character vertical-line (`|`) shall\nmatch a string that is matched by either.  For example, the ERE\n`a((bc)|d)` matches the string abc and the string ad.  Single\ncharacters, or expressions matching single characters, separated by\nthe vertical-line and enclosed in parentheses, shall be treated as an\nERE matching a single character.\n\n\n#### 7.1.5. ERE PRECEDENCE\n\nThe order of precedence shall be as shown in the table below, from \nhigh to low:\n\n```\nescaped characters\t\t\t\\\u003cspecial character\u003e\nbracket expression\t\t\t[ ]\ngrouping\t\t\t\t( )\nsingle-character-ERE duplication\t* ?\nconcatenation\nanchoring\t\t\t\t^ $\nalteration\t\t\t\t|\n```\n\nFor example, the ERE abba|cde matches either the string abba or the\nstring cde (because concatenation has a higher order of precedence\nthan alteration).\n\n\n#### 7.1.6. ERE EXPRESSION ANCHORING\n\nAn ERE can be limited to matching strings that begin or end a line;\nthis is called anchoring.  The circumflex and dollar-sign special\ncharacters shall be considered ERE anchors in the following contexts:\n\n1)\tA circumflex (`^`) outside a bracket expression shall anchor\n\tthe (sub)expression it begins to the beginning of a string;\n\tsuch a (sub)expression can match only a sequence starting at\n\tthe first character of a string.  For example, the EREs ^ab\n\tand (^ab) match ab in the string abcdef, but fail to match in\n\tthe string cdefab, and the ERE a^b is valid, but can never\n\tmatch because the character a prevents the expression ^b from\n\tmatching the first character of a string.\n\n2)\tA dollar-sign (`$`) outside a bracket expression shall anchor\n\tthe (sub)expression it ends to the end of a string; such a\n\t(sub)expression can match only a sequence ending at the last\n\tcharacter of a string.  For example, the EREs ef$ and (ef$)\n\tmatch ef in the string abcdef, but fail to match in the string\n\tcdefab, and the ERE e$f is valid, but can never match because\n\tthe character f prevents the expression e$ from matching the\n\tlast character of a string.\n\n\n## 8. EXIT STATUS\n\nThe following exit codes will be returned:\n\n- 0\tSuccessful match.\n- 1\tNo match.\n- 2\tUsage error.\n- 3\tGeneral error.\n\n## 9. INSTALLATION\n\nAG can be built on any system providing at least K\u0026R C.  It has been \ntested on \n\n* SunOS with GCC\n* ATARI Mega ST with Sozobon C\n* PC clone with Turbo C and WatCom C\n* Interactive UNIX System V/386 release 3.2\n\nFor most machines, the compile command line should be\n\n\tcc -O -o ag ag.c\n\nPC class machines may require that medium or large memory model be used\nand that ARRAY be set to 256.  For Watcom C the command line would be\n\n\twcl -ml -DARRAY=256 ag.c\n\nThe value ARRAY represents the size of the compiled pattern array and\nthe size of the array used to record matched states.  The default\nvalue choosen should handle most patterns.  ARRAY can be overridden on\nthe command line with -DARRAY=nn, where 255 \u003c nn \u003c INT_MAX.\n\n\n## 10. REFERENCES\n\n* Aho, Sethi, and Ullman, \"Compilers - Principles, Techniques,\nand Tools\", Addison-Wesley, 86, ISBN 0-201-10088-6, chapter 3\n\n* Kernighan and Plauger, \"Software Tools in Pascal\".\nAddison-Wesley, 81, ISBN 0-201-10342-7, chapter 5\n\n* Webb Miller, \"A Software Tools Sampler\", \nPrentice Hall, 87, ISBN 0-13-822305-X, chaper 4\n\n* POSIX.2 Standard, 2.8.4 Extended Regular Expressions, 4.28 Grep\n\n\n## 11. BUGS\n\nThe expression `(a*)*` compiles but loops forever.\n\nThere is no check for trailing backslash (`\\`) in the pattern.\n\nThere is no check for unbalanced brackets.  Omitting a closing bracket\nwill generate a \"Patern too long\" error, which is not the real error.\n\n\n## 12. NOTICES\n\nPublic Domain 1992, 1993 by Anthony Howe.  No warranty.\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsirwumpus%2Fioccc-ag","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsirwumpus%2Fioccc-ag","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsirwumpus%2Fioccc-ag/lists"}