diff --git a/.gitignore b/.gitignore
index 8b1e6e9d..9e37a517 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,3 +1,5 @@
+*_p*
+
build/
*.class
*.out
@@ -398,3 +400,4 @@ Module.symvers
Mkfile.old
dkms.conf
+.idea/
diff --git a/.readthedocs.yml b/.readthedocs.yml
deleted file mode 100644
index b843136e..00000000
--- a/.readthedocs.yml
+++ /dev/null
@@ -1,24 +0,0 @@
-# .readthedocs.yml
-# Read the Docs configuration file
-# See https://docs.readthedocs.io/en/stable/config-file/v2.html for details
-
-# Required
-version: 2
-
-# Build documentation in the docs/ directory with Sphinx
-sphinx:
- configuration: source/conf.py
-
-# Build documentation with MkDocs
-#mkdocs:
-# configuration: mkdocs.yml
-
-# Optionally build your docs in additional formats such as PDF and ePub
-formats: []
-
-# Optionally set the version of Python and requirements required to build your docs
-python:
- version: 3.7
- install:
- - requirements: source/requirements.txt
-
diff --git a/Dockerfile b/Dockerfile
new file mode 100644
index 00000000..e8f90b36
--- /dev/null
+++ b/Dockerfile
@@ -0,0 +1,3 @@
+FROM nginx
+EXPOSE 80
+COPY build/html/ /usr/share/nginx/html/
diff --git a/LICENSE b/LICENSE
index 39bdc1cb..471fbc92 100644
--- a/LICENSE
+++ b/LICENSE
@@ -1,4 +1,4 @@
-Copyright (c) 2016, Senthil Kumaran
+Copyright (c) 2024, Senthil Kumaran
All rights reserved.
diff --git a/Makefile b/Makefile
index 61e957f9..81a2da1c 100644
--- a/Makefile
+++ b/Makefile
@@ -1,5 +1,4 @@
# Makefile for Sphinx documentation
-#
# You can set these variables from the command line.
SPHINXOPTS =
@@ -27,11 +26,18 @@ help:
@echo " latexpdf to make LaTeX files and run them through pdflatex"
@echo " changes to make an overview of all changed/added/deprecated items"
@echo " linkcheck to check all external links for integrity"
- @echo " doctest to run all doctests embedded in the documentation (if enabled)"
clean:
-rm -rf $(BUILDDIR)/*
+deploy:
+ python3 -m venv --copies deploy
+ . deploy/bin/activate
+ pip install -r source/requirements.txt
+ $(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html
+ @echo
+ @echo "Build finished. The HTML pages are in $(BUILDDIR)/html."
+
html:
$(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html
@echo
@@ -104,8 +110,3 @@ linkcheck:
@echo
@echo "Link check complete; look for any errors in the above output " \
"or in $(BUILDDIR)/linkcheck/output.txt."
-
-doctest:
- $(SPHINXBUILD) -b doctest $(ALLSPHINXOPTS) $(BUILDDIR)/doctest
- @echo "Testing of doctests in the sources finished, look at the " \
- "results in $(BUILDDIR)/doctest/output.txt."
diff --git a/README.md b/README.md
new file mode 100644
index 00000000..7acf7011
--- /dev/null
+++ b/README.md
@@ -0,0 +1,24 @@
+# https://learntosolveit.com
+
+[https://learntosolveit.com](https://learntosolveit.com) is a website to learn C programming using K&R book. It uses modern tools, and is designed to be used along with the book.
+
+I recommend [https://exercism.org](https://exercism.org) as the platform to
+learn programming, including C, and practice with a community of intrinsically
+motivated developers.
+
+### References
+
+* C Programming Language by Kernighan and Ritchie.
+* https://github.com/jflaherty/ptrtut13/blob/master/md/ch1x.md
+* https://manual.cs50.io/
+
+
+[](https://app.netlify.com/sites/learntosolveit/deploys)
+[](http://www.learntosolveit.com/?badge=latest)
+
+
+## Author
+
+* Senthil Kumaran
+* Email: [senthil@uthcode.com](mailto:senthil@uthcode.com)
+* Blog: [https://senthil.learntosolveit.com](https://senthil.learntosolveit.com)
diff --git a/README.rst b/README.rst
deleted file mode 100644
index 3087326e..00000000
--- a/README.rst
+++ /dev/null
@@ -1,41 +0,0 @@
-https://www.learntosolveit.com
-==============================
-
-This is the main site with all the source code snippets and documentation.
-
-
-.. image:: https://readthedocs.org/projects/learntosolveit/badge/?version=latest
- :target: https://www.learntosolveit.com/?badge=latest
- :alt: Documentation Status
-
-
-directives used
----------------
-
-For the Run This link.
-
-::
-
- .. runcode:: /path/to/code
- :language: c, python, java, scala, ruby, go
- :codesite: ideone
-
-For the suggest-improve and better-explain C programming contents
-
-::
-
- :c-suggest-improve:`filename.c`
- :c-better-explain:`filename.rst`
-
-
-Dependencies
-------------
-
-* https://github.com/sphinx-doc/sphinx/
-* https://github.com/uthcode/sphinxcontrib-runcode/
-* https://github.com/ryan-roemer/sphinx-bootstrap-theme
-
-Contact
--------
-
-* Senthil Kumaran
diff --git a/codemap.json b/codemap.json
deleted file mode 100644
index 72bb78d5..00000000
--- a/codemap.json
+++ /dev/null
@@ -1 +0,0 @@
-{"00d9d9cdc121c2f7f4b67ae122308450": "aDBGYq", "00e2143bcb14fa5e5e0479904b778db9": "aXM3ST", "011ce23615f2cbb2e40ec049b86fd414": "QDDk5D", "01417b8700205169be6bd5839040f3f7": "sOyGvw", "0206f322c57ff87e317c221593f199c9": "nFqdZD", "0252b4bc0140be29d08a52f8a3606710": "6ui0jo", "033b50318b863b14465d794ba2e5bc6d": "LR2pFr", "034018f099da9ae1507c8f6955a42ab4": "0DWFgP", "03c81db672b2f8db5de0342d7ee747ab": "xkPjys", "0404c78249e0692f44214defa47badb7": "PUuaCX", "0484eff635813dac3d09afc919a20099": "ovriMQ", "06a6d73a06af5b4cd6eaf88f55d7d1dc": "fZNNnK", "075ce59a6adfb46727a9c69cafbbdec9": "r3mJgs", "07702eee92157018f31a3bf61654c543": "3W4gWU", "077dd12e53418ec30b5c652c50f5787f": "CicxEL", "07c35588475f76ce76006d6318ab2a3a": "oya0gC", "080f627bc6a1323d2b540d71c2f03cf5": "bR3UfD", "084b56fe2a86766d54a3e0198b701398": "ZLgaf4", "08ac99d79931e980f09b1b394b9a4991": "urtzXU", "0937cfc1a3dbc7faf6b0e0f99c22aca0": "v8Lo9N", "0953ce257a302dcd416ec5863d155220": "wgABjz", "098972249d9f1524f2bd11e7294d6d13": "k9Aebi", "098b317fe4ccf65d2c672b66b9e4916f": "tcCvg0", "09b0f5ebafcf85d22e88a1a5395935a0": "WkTGHo", "0b15423ee2f2cb64568dbd0fd6936ef4": "pRiYh5", "0b44e2a69fb5df650dfc5b54882a4cbf": "Y02Tql", "0b778a122070b27d5aa1df82e77cd335": "9Hs8E1", "0bd35d42f866eb4303b964c4102c8618": "hHdUip", "0c305fb3a137cbb3993e31899c596ab1": "kzJUpB", "0e0463d7c3693281bc10974bfc701bc8": "TLwsaK", "0e76a9780e4c7d1c30b8d192d6cb24f3": "yo7AEP", "0ef995489aa90a37c61e7d362db036e2": "f1l5nb", "0ff3e9b9557f802b767ba444e40bc175": "un1HZO", "119b02fd9cb186543829ea38b34909e5": "mvHxN7", "11ffa5cd695d9f65fce27d1a6b8c0fc5": "4JwNbN", "12bff77baa280f72b970cb5e6e07b700": "IDbZLI", "13555674a9dfcc2ae3f5a16fffa1af67": "cjDMWs", "139b6abc6b769a10f887fc4f7f30f053": "34f7TL", "14a5d10bf24c44e83b4e1f685b1a2e19": "oH69o7", "14ca3dd32324a92e159273d7774cd6ee": "dClJCz", "17334eb0a50bc158d802c83178404b5b": "wRWDVx", "17373250864f980c96391bbdd88be750": "ziUjXd", "17598a4d09bd2743f29a800662ec8634": "uCYwq3", "18028e2b7b61968a46f7750021d8412e": "43jAcv", "1860221ae7e3f15f1be3aa489350fc07": "bUmX6l", "1a229303b65d87a72f373ef47a2b6ec7": "QeCj1O", "1a4ebf6c830fd2528089540bce01c338": "1HTlfO", "1a82372457fce9fcb509b82ebb19092b": "hbPpLm", "1a93bb1268c0331f372d1e44ac483f56": "yun1KR", "1ad2605209066a68e2d8d5bb5908feaf": "EWCkNc", "1b5968055b457bcc2969a1f41b35e302": "pUoPEb", "1c81871ecfe40d6f73f11b7fd45fcc53": "zRzXDB", "1cc801604d6d5dc8f7651ef44c613f9c": "9wrpFI", "1e1ede444eadcfae7aa74a1da515e64e": "0rSOYi", "1e3ddc2498772d3b550fb256bbd03fb8": "ATVhMn", "1e496d88444102fe39278f1fcf8ac9bb": "0s79UX", "1e5f5900085302c517d43fff5b7c7323": "Ypt9T5", "1ef0c7712bdf9d7c7733d873553942eb": "BmHnbf", "1f071f57f77a932fecb0cd031bbe0742": "2ybgGO", "1f3435f7a5f0ca164549e3c533d97bc9": "cvLlA8", "2089577f61fab993bd2522c8f17df81c": "X9zABA", "209342353fc00e716d2463b329b3b396": "oAdUqq", "20b0968faa19b6dc262eb0493b9f8714": "C37l7l", "21dfa21e40c9408c6db35e109b2070bf": "XqKshm", "21fcd0c84e156918f67495dc95a17d68": "uxmbbV", "22a5ccfe778affaef492e8ecb55eea8e": "hoxZEH", "22aac93d8d78277e707a02ef95386b29": "uSSU6K", "23042cb3bba139f05321ca9baac8d499": "wVJNtI", "23341178089a20316e428cccfea19c21": "ffvvjU", "23356ea8c84fdac932eefe08ce2a7902": "k6TcAh", "236d345c69b9e4efece2c3c43eaf4137": "H2olKN", "239f802081dcfe944637441465dbd886": "Ux5ZVD", "23fe4005d03ecc49db491a4d73c16db2": "W4uXAG", "247419a0b2407c3695214057c19d06c2": "QNeut1", "249a4f7265b622d96efde2f32f770e6c": "JMxU2u", "25378ca6c7e67e7cba53c07278ad537b": "fK5wi2", "255c9ff380bcd0cbac530057239f33f3": "PPSpym", "2564fb22c520ec9611c66e81cdbc1ce0": "rDyzRP", "25c590a8df4d8c5b97fc14df2e5d750d": "nAEcOx", "2652d48609af2d4be15be0bbab1a801b": "1IvWus", "26edb72e502ca0969fd537e07b60adca": "NJf7GV", "273b77bedf5843c150d03e4593475edf": "iD8TSU", "278c8bfcbf5c6679376a056c1d9f55d4": "4Xk9Mo", "290859c341d0ed3b29dd0d81f19cceef": "YAJepx", "29529f66349da287462c5e4e9dd858fc": "Q5Yi2e", "299145d539b47f8812a1ad50a8c4730b": "V3JRLX", "2a912c36809d1d702f7c331b2971ceb0": "MPjXuM", "2b3835049657ee39b614bd6246cf054b": "HTEQ1y", "2bae50a9a192e3ab52223bcede915b77": "CXeU56", "2bf0fbe99093221de899f3752fb2af5d": "hy1zSy", "2d1ac09803474845d3b277a473f56844": "BmyYcj", "2df033cd9adb67f3756b93be62eec2f8": "dULCrL", "2ea24ed1ae852e6359f0150b43311388": "DdYH0J", "2ef0a9eeb96a1cad4198e0fcbedc2c68": "jscj1W", "2f69479116a9e3b98e57db48aa0bbd37": "PLRed6", "2f72486673de4bfb73a7334721678be6": "swbQ6H", "2fb4b3ff6409860b9c2aef9a29f64691": "MP7W97", "2fbf35600698387d73f472d99fe8b212": "WvXpEm", "30256344195789053409d38ce8d9bc22": "3CA4al", "3192fdf5910cb18c7e502006519d7cdb": "a6N6a3", "31aafdf7f705fece7156270a9e639031": "yHA3WY", "31b513228b87a0e958eaf5528ad1a831": "GFEmcl", "32508a5e8f931e4d52c190c86b0df4fb": "wZ3WS3", "333a74e2b3dc14c9c51d8fb995c80904": "i5z4J2", "338a91b34a91b8c02d2f5c8fb40b8d8d": "Ytfpev", "345702dcf4aaf560d036d0e74e84e046": "xXVQkF", "34c065eea56bd6bb0e141ebe07cdf81d": "TPAJCf", "34e52a6379f63a62347ade5f6b9005dc": "QGwjhn", "34f277199fb48867873773f7b1112966": "PTqdv9", "3560228625ae5ab570e3cdd3541e02b8": "S3nCRy", "35899ec14d4615abe33b7574de6096d1": "mJB0g1", "36017fe3af5e53eab15dfa9382ca83cc": "UybmKm", "3618bb44b1ce7d975da881b0d49c732e": "TEZf9U", "36294cfccbd411c5e8c1fbf8ffcd54c7": "uCBIfp", "367ef8e10412ee18b39c7d2447f61b7f": "iloMDW", "36ab82be3eaea557a80d0e2567e727ee": "87TaJm", "3782eb41255b5a2f4290bfa54af5cee6": "qNReG4", "37a72b54aa06e71c540dc57f3ea730f1": "H3hDHK", "382afccb33a9f7b0105dee1a63cee11a": "JLIhIz", "38bee8826e7b363909bb89d233df1fa9": "i4MCAe", "3a60adf4f28da2d9bc8f153f0aa9964e": "y5VS8F", "3ac9fdc3560b18f11cb9f2d8948891bf": "vK6pUz", "3bb5f3425ff6bcd84d89fc62784027dc": "Efv3SV", "3bdbc85c56410c09c2e451e85165be30": "1nnQh8", "3bfce164123564e96ab6c93796cc42e7": "IjmB77", "3c618ccb055103370a6475da31fededb": "5eBBEs", "3c9adf90dbd0067c9069e2e238163ea0": "0a7kU5", "3d68f909c2e6e8547df1046eafd422e9": "zbRdCh", "3ea20b4ef4847f744de2fc12f044de57": "bgqFr8", "3fc2eeb85d854447560b00c126fbbbeb": "cWSWV7", "3fd8e2883a735a89152b1af03cfbef58": "JWpZZN", "405cf710e1de4310f9e25179f45e45c4": "Rh1C7m", "4082bd918da3718fbafa828fd5630b94": "9l37Ke", "40ffe11029d8bb0d39e10b90b6273fd1": "esoECv", "4129564a1c7b47b00ec0786993908120": "sJMmWm", "415371d3a57a055c8358619e638a8a9b": "8pA08a", "41af8d777f50b1f3b7e91ddd071dc709": "fCnOH6", "41b29708372aaa34ed318889e276fed7": "JYaK6b", "41b2fb98574cf6393373cd0c8a56f6a4": "itkwbP", "43529d2edd67fde1ddea712fb2d96993": "6RvXk3", "437ab06489449856f1e7e2fc615cf61c": "Ifi9gZ", "44d3b7b4c2e3c806995281590473c901": "onoEZX", "44e75a6370a71a4616136e955871b4ac": "sCtx00", "45642cba4f4b88fc7cc769b370686e18": "ByRK5C", "456a89c10f2071be14b355802701a183": "W0IEOx", "457c55b915658dde9cf41c43d4e430ac": "bXdea6", "460d039b63991a742baaafa48ff32634": "FSP6Ly", "461195f3b4e2ab020c15568218b3ef24": "ylUotq", "466c73c64e873a9804495d1ceaba0da3": "jmSVNu", "46b92265d670cd084c80c5f44ca59de7": "SPrNme", "46f601d3f0a9a9f7a35d405dd8b9bcc5": "1x9TaL", "477b47af995794138427f9313aa24104": "6mUMmL", "479b3cb97b8654b18943e0ef7933b71b": "6n3oSs", "4926a6f0e4606d663f7fef0c56566fcd": "1WMrfs", "49472d029cc8bc6a885ca03aabb14db8": "xBPBwX", "49ed263062580f5618eb1d3a2eedadf6": "JLG9Ez", "4a1c7f5cd85f3f2893b80110f0e50ef0": "3em37c", "4a595547d3ae1c110f9f8cec040ea9ae": "u81VoO", "4a5e1c127ae3e9de050cb882956493ed": "8tSek3", "4b092d10f594c3d5c0824acdcb839f55": "rnHRA1", "4b67d0368acabf3431ba3ac222b1ff85": "ujrDy2", "4ba2953ef46cf3384aca2a85ce049f5c": "zwvk68", "4c24e50204da109ff1fb1bba5c7125e8": "wX06Go", "4c72ff2827c307925dc3fb620b326b55": "4O7NsN", "4c7ea9a9d8d8e860baa0cb20a6f24fc0": "Mx0Ztt", "4cc9862f8b3e5d61781006d747d734ae": "bswLvv", "4d76af2dab4c75b1ff24bf7dfc72dbe4": "mSfWdp", "4dbec780db03ab7a876e27787494d59d": "eAfg4q", "4e16ffbeb01541acdfcc5d9ad9d24463": "mbRTPo", "4e7e856d7f497d19142bd271591b14b3": "AKQWpB", "4e9c00717acc4b54ea3b346c081d978b": "4XWz4c", "4fcbaf3639109ae48d4d5562d3dd1f79": "BS9lX0", "5097b6b431c3166131dac553ec155e36": "QORjTs", "50c799effb7410fb5e173627cbd009ff": "I6O4RU", "510b95b030f69ecd3875d090b77971c2": "kaxTJT", "518273c19df9f2f4a73db81115d84cd5": "9oZ545", "51db31c7a9f882a30190a8b11d977393": "kZNzIZ", "52198ac30e61c21b622a6255d8e3b556": "c5HMDH", "526933a4bec1b1fce8b7f338556a42c7": "xBSFYE", "53443cee1831850db5fcf17ad7011b66": "v1JIcO", "538725eaab346486698ffc7b71dbe1ff": "37yQLS", "53ac95ff2fbe7ca732d81ff1435e9fd6": "wUmwPm", "548a4b65370fe443cfe5da16010f6724": "QRFRka", "54b4f778d9a7e244b7345d9399bf40c9": "R2v9p2", "54f383324d156d346ffce552fa5368a0": "2djhgk", "569de57e656eef0823bad7aa951a3ad1": "s3tdtA", "56fa41d3251032cf413747a1c04bf52d": "T1ycP5", "56fc8fbd97526d48a1c58d1c8d4cc0a7": "D6kxZe", "57ca6231995c1d536a3d7883aaff1b41": "BFKNEZ", "57cc554c9e06adf00046e29b792138b8": "ZD7gLK", "581bd2b52aac85518095a3e2ff1fbc89": "0YU5uJ", "5822e35b1e2ea0510e81aa2e4a31250c": "bAyqjK", "58f71545eba5cff6b08e9af44d4f48f6": "bb0PyH", "59a763fe97d6711b44ff8dbce12725e0": "hwyuAW", "59ccc9587dd36be7fa6e89142e1bd585": "666X1e", "59e50e91942a9a8cb1a4f16fd014df7f": "Oit7gp", "5a33c52bab689a057edd063c15834e74": "LDpYcO", "5bf5d848152230a0bba58a64d75a1825": "aAn6t5", "5c18ff4b773bfb53807cb1b9c53efc70": "s2JAyO", "5c251158c8ac72cf9559e5a5ed17dd4e": "pM9FsQ", "5ce4e48821432e424c8f839546d1e6ec": "bcPoD7", "5ce7545f948086129592131003838377": "b7cLmT", "5dedf65c8171c537817bcf442d59f1a2": "S3tWCH", "5e3e07571bccf90e286f9a7689a29e49": "VD7gVM", "5eea3268b4f07e867415b774f4822106": "IwZzKE", "5ef2c3fcbfb6b9d4704750cc46260e35": "zYaxsj", "608da449b4e722638695065aa5697135": "VujsXn", "61214ee1af61095689b68f81906587e9": "Xq3hcc", "617ad0790a2b008c9e8e648591efe1e1": "aVOUjp", "61c7925481ae38ec114aba2a91cbc542": "VNLuDP", "6260ff37f33ead0055d212c442a80c37": "mdmjZw", "62773453eec664ab6d73cb7fe0cedbae": "E0U0RX", "63044e4ebfa225e128c07fe185df9265": "Mgwpq8", "641bbdeac9c29f16850f72a50aecb38b": "pmz7lF", "64231f6174642f8ca9bcbfb3a8e9f511": "pFbZAj", "643d3003d359f841c2e04c51aa9c68f2": "mID175", "64ea56b7381270469b07026e855a8dfd": "Pm0uj0", "6548b1b4bdd4808995e217687bf8f887": "vwHwC8", "656fe39a9618f2464ff084a01cfea135": "DfAmue", "66f9ca747f0490ede49c032f647860b1": "sZop3a", "6700df9b9a3b49212dd7f475a6d1da09": "m1O8wI", "673f49d5eb13e3745ddb80a4c2b33790": "MDyBsr", "6770e8a234f24420450d74803d976aca": "Gw3WaT", "686cb02f1c4659ce9851aebf0cec25a1": "ao9ZGb", "68aabd4c4646fcd08c52f84d5385dc30": "PXtGHg", "691353ea6d0edb7b4b8c8b2088d00979": "JBS7Rr", "69310d5a50bec4d0ef508379c6ac1eae": "RIzZKJ", "69762d156a1a171ca0eb3cbf7d491b54": "j24tdW", "69e689ab506bd7634056bd6b95dd3457": "pWNyqs", "6a5127a5ae3c35f1dd439e4cf70f8408": "1bpvbU", "6a6ac1e5f5e41876681d31aef01a0872": "t6Tiuu", "6b3435e77dc88b050cc49654b363a07f": "GyuWbb", "6bb411a859a63f0536e9383da8bee5f4": "Lkdltx", "6bfef91284a8dab6b1d574bb61039e2e": "HKRvok", "6cd342b22c596b43aa34ce975917b579": "45VBXm", "6d06b3fe18b9a2b7fc9e9944d3f32331": "Sfc3LZ", "6d3e197baaa01115917727e9859f8053": "uB6S6W", "6e2dec6d6f68a1838c4c024fabd2ce74": "qXSaSN", "6e5873ee5ba49c06f86e7fd9a48b6517": "kMpu08", "6e68c7ac6a7a3a5df4db8fbe58dc6c73": "OIJkjX", "6f014d4bc1a315b89852e591ac3b098f": "npQrzA", "6f08112659d765ab411c694956d99e1f": "BifNLh", "6fc4d58046ca70fffee1ad5edacf2b4d": "v6BxdP", "703c3cb07b6f069768b87841996866cc": "Svi8qJ", "7077a788b83ca98639d05823bccca41f": "aJifis", "70bd036c5c11e441b5bb2676da45ca60": "esdmyz", "70d4e49eb7d839d4554694c4fc80ba1c": "PT10rf", "70ecc87b6ece4f2666a7ce188c2f64ce": "wP8Go5", "71b206b986b39ac7b783572b80a2ef97": "CtZv4R", "71c3c8e473a92e099fbb418bd226fd51": "iw3kT2", "7200c09e8d0eb5f8369eb4f8fad3d758": "D7ruaQ", "7208f1715c64791cec3aa4a59f1ec3a6": "Nq45QP", "721e225012de6178d9c364aedbd807f2": "UJZtdO", "7249c6b2717a436011fc48d259ba2c77": "xx2hwz", "7359f47e8abf26270458560b368af413": "ffCjjn", "735b2aa97f3f16471e93e1d62cdf85f1": "O6AF93", "739e87d5c6156229e7b458ef4d20723b": "gyJGjM", "74a6962cf5f4d35987419d333597f054": "wJIcLx", "75250987feeb1d9313a213e200e8c7d7": "4JWpDq", "75324469283865a7ebd591f3ecccbeb1": "6izPba", "759b7030b60806b84ae040666100b41b": "hCrlWh", "75ffb917345269bcabd46c2a176fd595": "C39MT6", "769d536e5dcd4783876cd2dd626a22cf": "5ODfM8", "77fbedc306689793a268205fb2542940": "3CLHcT", "7818ebbe8fe5baea78437971cd5a28ae": "RfJQw8", "781f86275178422f6e18bd1615a3fc93": "0By01m", "79bd79779b3e50c4d8350f5d40b038db": "lP31K6", "79d83d5544e3d2e2d83e185fec24fd29": "eNapeD", "79eb6f04c9dce7c43760bb24708e8268": "JuOcBe", "7a5512bfd66144eaaef056c66861b533": "NxbAXH", "7b768e6a6b682a870dae4ac5603c3dc2": "oVYWZA", "7c34f6a5d5c5363fec465c30c9f22b7f": "QRBCNj", "7d4a9a34343ca7127b5a34430100b526": "Z6D4Vt", "7d9d64f6fec850a2f01f191ed7324c82": "AHhM2y", "7da68cad822b67fcdf299eb721fb3fa2": "A6UxDQ", "7de622a5d5d50cbee227ae268d756fa1": "RhW41M", "7e254440e0b3d4247bdf75bdd0cf4c81": "HXD0os", "7e5fbb086b12beeaa3b5b64fc93d981b": "EnarSD", "7f1e0e40b63a8781f3efa20b1de1df37": "oB7hxf", "808a4de3c8e36e41500829cb7b86fd8a": "ghkCHz", "80a0c7bd4a527d7bf3c344b244568eb8": "zzAKwF", "83462e0da479b7b47ba00f99b1ee9912": "SJE06K", "834982b47ac67c1724fc49f60e64b31e": "Ax7Raj", "84218509a634e0577bf1f34e7defc2ec": "OHpFfj", "856c1aaf6b5d505dda2e66fbe69cded1": "1A2f4p", "85f5c682d231cee8b629eb00409cd16d": "kpzPYX", "860641c83670979d25fefe6412cf3825": "VmzKX7", "86347a19ce77d0249ee0939d128125c8": "xKpDf6", "863dab89f3b7a9f663e4ebb07c20484d": "vdblrr", "86c88d228bf447bb220baec820857382": "rnVyjX", "86cf900ad3d4febd0f32634c2bfb29bb": "R1EJ5u", "8734fbdd722f5ff8bfe2014e6d1a955a": "nmcmPo", "88926431b04e13be7fd22160b5aa9b14": "quhHw1", "88f7e10343289c087b259a7a4beb7bca": "13NRWm", "8af1a119b6df3333e30ffd27f84ddb17": "jXQJ8j", "8b215a7cd85acf5290e9b2c6b957c2a0": "0tPo46", "8b8441465c558c1a8e06f1eb68a7ba32": "5NoiNV", "8c0b2dabd366ad7dff964f09ff82aec7": "ic0WuV", "8c3bef73e43bb7c17521e19e1c7a3102": "dkOinN", "8c7d5da431a1df5dc9827718ceed2bd1": "SnyqKH", "8c9c1da91a3617a8710b95c6d571f37e": "y5U4vH", "8d0a864e74b5389dec21af665b531190": "VYAaFL", "8dd8a6d0b5042602a854148f9d25dfac": "ftSQik", "8f54b179364927de631e8136fe481432": "FrybiS", "90de46afa3e5aaa7655f139466a03975": "wFpJ43", "90f36cdaee2bc80df306751b010c3157": "E3nHGN", "9177de3ecb6228e204c0f8c85f1df87d": "PP2GKh", "91db9a08d78ebece872cebc6066009c4": "3fq7dv", "91fd7fb85ecb1b262d7ff1f10a3700b5": "UymnpM", "91ffccec8abf2a59f16babcce220f0d1": "mCnmo6", "9220c7c562e35d691398380baf5ba44c": "qSrLyC", "924c550fd44d33ce5c43bdcd68aea77c": "xi8XKp", "9316f21b9d68230d0815ea104df5e54c": "zjFF9S", "9317f0999471dcae74ff8842f34fffa0": "NGEEi8", "943918c7ba0ec22d7ac7bc1f2ccdb82c": "5aZf3b", "94c224dff1b200053f5dad5d1e79caaf": "6rL6Lb", "955407807435725dc074370e91c49e80": "ODc9vh", "959ab0301f81944db128477205dc0da8": "ZEoRg5", "95fe1558911723c4d8ddbe6ec49514f6": "iAUJLL", "96a85667e621ea08471c8649fbc5cc22": "biOry1", "96d7784ad4e6b688c767d1393ecd6c3d": "pQLfi0", "9705a0a9410150e0a686427d08a07b88": "HPOjVT", "97410483be91cb6dc9c75b08d98d4537": "3LDPhM", "97ea08e52ecfba9f893ee223fa2cddf0": "0ydUcv", "97efd072f28df5cc33c10f898f91cade": "pICZ6J", "98354e3ea8fedffbe03aa18f51531839": "NgtwMl", "9850414c27e8b9a1bbb3cdd890407ed0": "ddTtFH", "9866ee350a9f7b2c8c97ca4cb03ecac6": "mDEvSP", "98d83cca8c71a6fb8ae0802a59704571": "MV4Ba6", "9911a7d69142f219f1cba23f1eed8443": "nLhkTT", "99320de70ddc193ffb6193a1a4b61e1f": "PVYli1", "998aa692c65cc11e57c6b0922499ccb6": "QcW8hz", "99b026e9a46a11207e65c7388164fa13": "Xb2Bfq", "99cd14ce4010720d8e4c6c028f4cc652": "CMLrbO", "99e3347a0accfcda4d32a7af4de93d02": "VIrXRs", "9a2293b65aa529034fc357d9dc3464aa": "P0rmSQ", "9ab7ef1903570456172bfaad0c1625f3": "pR52IA", "9cd6de6e16d5db206cad5a663118eaa0": "WClIda", "9d4238854b10144cc1ebf665b640561e": "onZ0ul", "9da0036d56b2b4aa83ef920e0ee872ae": "3oPF8J", "9e1d398a108eed08e933bdb6a5700965": "7jfGTA", "9e859c1e8f14475154e37603bbaefe66": "Mqhnen", "9fcc678b5d4a81371689b96edfffc1c9": "6NTKEP", "a013abc276ba980331f7053f2822f1b0": "P4ayzW", "a14722a30c847fc19b7429fcaf2d6724": "jzZJK2", "a160f160828f4d60f418032681642d9d": "6rAhcs", "a1ed5c043060a9f2d9cbb59deb7be1e6": "oRduOs", "a24b5de5fa475f9495f85acb20efd05e": "QjQVRX", "a28b51ed483648285241b810f549f0d7": "5Y2foQ", "a3fea72331188a4a2d9288599dc4eba8": "9zeg5F", "a4c629aa92dd8d53d94c7452eeb3f123": "zFS03K", "a5777476a8063c00cc8bfb50f7959929": "l98CMj", "a61802cc17affdba78ba02715faa6f7f": "849kR6", "a6cd247158937cd9e6994c12649d3379": "Rthlaw", "a6f5c2f338a8b76db0fc3d91cf269d46": "NwmWJ3", "a70f8648b7eb484b858c386085cdbac3": "vR9Um1", "a7c6d3e939e0f237eba89ede8c4ee0d8": "2naguo", "a7ddcecef5808354ef76994d3299d963": "PBe5c6", "a809092b4878cb3bbe397b69023637d2": "ZFuR9V", "a8cc09ef8a49690c7bba174e722b85ac": "RhbDJl", "a9f5b442351493390b672574a3d6201d": "aWwgPw", "aa3fb7b0e528d7dc93091a42ba5ca2f6": "At8mEq", "aa4d1b03fd9db9e0ae1a7fa853b578c8": "HaTtq0", "aa9c5316a8f082bab4ada96abdafe3a6": "lIip2D", "ab5701f88a3bae6a111af80d4c3ad066": "v6oZN1", "ab9832d818ea8a0ff9bbe96e0306c4ef": "MICrWV", "abd4552cf793e96ecddc745660c2a236": "0G3K90", "abd4f20e92a6e907da455fdcb05c80a5": "IDsn0Y", "ac5bad35ea85564ff4c74f99b0d709b9": "xIs1HG", "acf7f9a73cce20259be98166686674aa": "3YraRD", "ae08c8401165ed7d51e588f9d49f940c": "Qiedrd", "ae1e26d0ea08d737c4a7c37c411cf878": "bEA7hL", "ae1e87beb2f6b8c0b94ccd956480d0c0": "j44U70", "aec49e6ee1895c7af62d14a24a43f19a": "F7qTMS", "aed128ddb211adc9c2edce3bf7900f7f": "YEckkP", "aee3c87cc3efe49c85102b72e68834d5": "lSx6fs", "aef684ffd036bc862519ef22cf3bcd9b": "vacAuf", "af3f887397080401f1f6af910fec288c": "r5r6HX", "afadcc0371753413e5d5aaba4ad5310b": "v6gdat", "aff63347df21766d6f7f1cbbf99629e3": "omZaJx", "b000d76fb4df5191331b1d1678634f29": "7iIDio", "b0025f65f266721c71dfea4c6dc6cddf": "5QUDVS", "b12b7374e47efb54f69dbcb8e5af8146": "pReyOw", "b2bfd5f0ed9fd7774f3bfcae96c008ed": "gckUcn", "b2f25b2f5b84c3619430f642325a6a0f": "bDaM3w", "b320af637a950c4315e2afde4c11dbe3": "ozqyhd", "b32ddffb492d550bb427b4123d7a54d9": "OqXLln", "b350b0d564178d5c023835c6887a02f4": "XWDZB0", "b3eed07b49c6fb3393f0a9481bd4e52d": "moW94B", "b4914242810d82425d8558403f604de3": "7E4F0B", "b49450cfa3176e984eccc63c7f02aacd": "qp4W27", "b4ea64d7795c0cfcbd3f236df83657b2": "ISdidH", "b4edcae4da50ea5365245f86839315b9": "1bOKKL", "b50700bf52c8026f88272c36e3ba347b": "KWkbvY", "b6e1279bd63fb0842df5350d7a80cbbd": "li2SdZ", "b710f58063d3f5b99fc23ad34338cfa0": "wogO8R", "b71ab35ef5e1daf22c80622db5b67c4e": "QsJ43t", "b73672b191ffda7fbfa81096b2bf4746": "F9vakc", "b73823e867947ea8352c5ca206e20917": "IPnLkW", "b77b75d3a257cd781e2fea12bcce5919": "ZrwNaN", "b7a302b19db4149cc3b9b68be53f53ec": "JsgdTR", "b86f92ae4a3d3ff59e7a337af5f22938": "An2qRA", "b9fbc55da2c73d87e6cb978bd1c2aac5": "Tvp1FX", "ba019f8f9a9b112390d149e5c75d7533": "wtvkUu", "ba89a8f6b77aac12fffd163b2dc8f64c": "Sx8gHw", "bab734d0bdca57429d4688ded450da1b": "HpoEWc", "bb07e2c632886217f9c02c358b823c23": "9O0Kzw", "bb0b0b357378f765b9291a40dc3fcc62": "XSe4cm", "bb0b77965119f0e3edec8571e3a2f601": "4Ogpys", "bb90e29eabe582e073ab720a66708382": "fav5U3", "bbb2558539f55f715ad58d62ef357242": "1GIVX5", "bbff1a70807d449feab29842b2c9a307": "EGhIL0", "bcd375be628937e7bffb5ce24e05455c": "RAYmrn", "bd116dc06b240e22a6d680a89ba2c728": "SicWLU", "bd3f03dd3bc131abed4c0c61aadd3671": "zNSgiM", "bd5fbaa7512a26b674a7d8919148d0a4": "UNwSJU", "bd9128b366256cdb46ac37db7787564d": "1RMfya", "bdcebd95572cb2bf41ef252e3f8e545c": "ZtUHbX", "beaadbccafb9a81e95c7cfd2a3a94e9d": "zyLUbt", "bec7c90d007bf1ca939e6bb0e19c0349": "4WiyRu", "bf4a45ec6225a8465c630dffef1a1167": "PavoKU", "bfbdc9c3f38f7dd02152cd6cdd5be9fb": "V1DthS", "bfd0f7ca1682301d821eb8d4bf2c633a": "jBjmZp", "c0787cf00be5cf7403323c12ddd94178": "F3k3qo", "c1bedafbb76523d5af6361d895d8a76c": "WV3kI7", "c20e5e87c94f00e2000915b958b09774": "BcIXhk", "c2220f408598d29cd32b0b58992bec5d": "s9I7ij", "c23a99ad3f2dcfa1051e3d1efe8b90cd": "JikvMD", "c29fdfee8926ebf13ccb66ebe090972d": "GTMip5", "c2c04960af41f4b2d933b5424a1046f7": "Ra0D80", "c2eb8de00039ee52bead534700662932": "vP6i4C", "c31d313093875b14bc88244f6b322701": "qaaExa", "c3b1a778c2bf711e837d6837fa741acf": "Spf1Lk", "c4091aaa78c5faf5960c4fe519c0dc62": "mHrjvI", "c4d7e1aede5b8eafa0cbd2a81c1a8c9a": "gfJSNL", "c505af22132426a70a97b7cb51dca070": "7Af88Y", "c533a4a156657945567bba9dfdd95377": "FIeVi4", "c552138dd116333107f284d11e5d18fd": "3j3pmf", "c6147c14ff0688cfaca99ea087c0c257": "vnu4Jt", "c62179eed44a3734bce5a34470196950": "VoSNBB", "c648f2f33edcf717cb182f794295c481": "QGrIIK", "c724b8030fbd9c6f22bba744434f044b": "asZ4hQ", "c7372690825b18ab52237a1a97f4b06f": "X2l4EP", "c75005a75934c6f40b78b8e349adad1a": "iU0V1h", "c75d767c339c7500e858411a5c6b9751": "WiHCdL", "c7b61d6ef1b9e8057aa6f3b93d5b448a": "KE8zr8", "c80503477534e486bbb97203e21a581f": "TSKMVg", "c8411bbe6ed456c89c6ec6ca84e46cee": "QZvuiM", "c872e9884eaa5e229b09d70ac8484f7f": "Jo189x", "c8a34ac2f783448424167c25e626c3ac": "QEXGNu", "c8ea821a598d10b82b1e5561772dbf0e": "9WuNI9", "c9a2257a6aaa3d33afc7891ce3ed01ee": "j9VkcK", "c9ac84ec253a7784e9f033e38f8df831": "pn12NG", "c9eae2a50fd8a37fd06974fdbb8411b3": "lNzWZH", "caf6c90ab215f3b898a2a974dde5145a": "TwGMJs", "ccacafabe512a7e89599f9d02fc6a086": "9HMJ2H", "ce6b6ce9f688e1392e734186d3a57fcb": "kaCSTw", "ce8afb23566219579471b1d65399941a": "bpCM8l", "cee3f1b157fd4c63c348110743cd6359": "mXXWyD", "cf14c1d4e5699e22367bee914e353808": "Af0ys4", "cf21191feb75f625570adb3d386ba7fa": "NcIMiC", "cfd42f24f7738a9d1300bdd8fa99befd": "rhvSMP", "d012627f48103f7c87a3cc6af450eea3": "XOXiTZ", "d0cfda60ce66bdfb906dc31c1ef428f9": "t3XpUE", "d0e4f1cd3ec3c885ac81e1afd7c35564": "Ro89BO", "d181d62306f91212feea923efbc5b7f1": "Mfiz1z", "d1c7082469a9e2d30b54665af651cb47": "l9Wuvr", "d225c8089ac9102cec9456a3c9bbb62c": "qlSHOT", "d23d857ba120a9166b613316011befe6": "Sd7hwk", "d287f2f8821ea3a3927239242afde683": "hkfERs", "d2e89e78d7c3f3d33e02cf7a0cd212aa": "Xz9Pg5", "d317cef54bfb88f2b8d079b4fdaffce3": "aOpMR1", "d33e123b295d155d0057c7a13491c7a5": "pvHCBE", "d41d8cd98f00b204e9800998ecf8427e": "rFJzKF", "d4e358a261ee3855c011a13ebe7106c2": "GyJ46g", "d52d120f3ffe53c3bb4ac96e01140256": "sdjFzx", "d858237b832c02cad1022800c87e85b2": "mB5qCS", "d946ec17b8da953842f32ae535a7a1e4": "Tgip6m", "d9a3e989d896f4feae861b23a4d70018": "kHjSQj", "da7ab34b49227b8f2857aa5ddbf4b257": "IMK8hy", "db00f4304e254c0d4a8bda7116510ae8": "IHyFYa", "dbc8c60ed470d26f5a301486b9007be5": "zOUZsC", "dc66efdf28959720e2d1c097502b9b78": "oEuEsM", "dd6e5a395e95253da2aa58a1de98e496": "XsmZvD", "dd84b1ad65ba637eb979c709c83bd47a": "K8UErc", "dd9d72fcc094cedcbc6cb910646a3a9e": "JUC2Gg", "de58cf4b45c0c72922c42db31f4a69e5": "EO5umY", "df86e779dc56d0706ff78d92891fac01": "913fpA", "df9eb6228cc882ae027d984485a789a4": "HI4Z9J", "dfa2df193655f59682ba947de096b587": "d3M0BM", "dfc9ed04596c723f67d639c0a2dfa9a0": "K2ZJvD", "e066ce5de88136cbd87c5961654e22f4": "4zLC9g", "e130b00baf1733737edc66cbda90ae10": "9kQAAP", "e1be5422e43aacfcddc72e1493ce231b": "ZNnr5K", "e22cf676ff4852c13e5c1da089c8e616": "D1VFQD", "e259e4af1fed4135a678c9accdaafbbb": "z1mhZh", "e3354055aeaeb3c87347dd95eaf431c6": "E5mi7e", "e44d3d1ae1458bd96e75e653bc0bee68": "MT1xQi", "e4afed600a4134e33f9d55efaa3a3b13": "NKGPw0", "e5515d7484afaebd9be77f605de98bca": "d39TO0", "e56dc95035095b22c4871ddd19214b15": "0ujCjh", "e58201ae4489927e53c7771e2e1ab6cd": "TV5RJ1", "e63121fdec2e23fb55f87d9f6c89a20a": "C7d4dN", "e633900df216bed714b28527ebecc595": "H8OEw0", "e67524bc869005dac90d30dbdf6f4b6b": "kusFJU", "e6dbb8678ba86541844f38fbdf9f9962": "7BiJ63", "e70fa2ac9e3f6a70e042b5662d04b320": "F7iPTE", "e7648a93766e08e8cbce9ac71cc00a1f": "fAe9VU", "e833bad8b1e51201ec9ff33281b7c7a0": "nAtnTK", "e83c6f83369141714fe247f9837e3407": "62kHJw", "e852ad3f3be3d7679d48f5ac6eafcc4d": "8LslL7", "e8920568595ec74b4ecba442a40fe975": "i1ACKH", "e8da86a08fe4097b0f0bc248e18a8267": "F7GiKB", "e8f4783aa58191acb361bd425ee0821b": "1fEPVQ", "e9d00ba1a41cb827e70515ca81dc3b6d": "D19YmM", "eb38b404c151d19c981e6263499fb51a": "obX6EA", "eb66a7fa866945879543f5150aba72fc": "YBRu0R", "eb85ec762d767029249b4cdf7a739f50": "KcJb9N", "eb8be1c977c8b8ace5d562723eb9c7d5": "mjfE6T", "ebb37d172e27c0fdc7ca708eb1c53a25": "13ALUD", "ebea5f98611f42b3ebc9ec25cb060c3b": "QvhIK5", "ec117287383785d8ec7c14e9d18b4abb": "HdQ0xY", "ec224acb5c74da3a541cdfbde6501895": "fBAmRl", "ec489d71080beb740e0508db2e5f6f1f": "tmUvPV", "ec6f46380bec2ca00c6219bdf2c06dd1": "9RmuVK", "ec8a1ba5aad036a07f05e1be9b0246f0": "xlYSR9", "ec90240d90c211768aca215dc9ea64fe": "7vEZY5", "ed3a882092122e78bf71e6cb7a3e2769": "aTvAPh", "ee50f36458172ab4fbd0b2bbf802a5a7": "gwEYTP", "eeca677b9be1c866e23508337e53925e": "teKmvq", "ef2cb14c35a37f0f4b8e07e0968e150d": "6j78IA", "ef5e67965d9edb653d01928ca0013926": "d9htjc", "efdff8b6822ab048ec8f153a617d4df6": "2h4Acd", "f10fc10b802dea9677a2e1bcd622727e": "3QF9UO", "f1d7a9b115fff218bb11cc155fe901ba": "lxvR1W", "f1dc59dff6f0f78bffca77a0abdb06b7": "CRx1TX", "f202e1c7bbd7e4decf61493fad965bfd": "wt5slm", "f210df3826e74727b055c83f9d3d13bd": "2f5bQc", "f24c5fef8c90f4a490c13c9e9b31942d": "uDu9Ul", "f294eba4eb12caaea6cc83c54636ad19": "leztls", "f349d200b7b3555895fc6addacec0979": "GSrfs8", "f353b8633d3211c9e1bfdda02f51feb5": "zUIcm9", "f40911f472378789b16c91e96052e81e": "EOf4xo", "f43f50936fc4aa99cb627cdc9b6330bf": "6B47as", "f46abe5cdc92c7a47f9dc6ba181ae951": "TKeIIJ", "f493e20702f74b0d29109aee43ff76e1": "wKvwVO", "f4beb46d55e210988d686d22b31e5b04": "PEkvmW", "f4e5d9da4a78aa5a58acc03f19d00dfe": "lqvqF5", "f5f59f055a9912a1e9ce99d333d6110f": "OJbvYL", "f6080e5e9a8bae92734b2cbf1664d6b2": "uWWzrY", "f60fc6641e1f39a777db41a99a832ac4": "0LQg7Q", "f695c3dac97a303d5bff8105c2051b42": "xDODG2", "f7011e97ff3d1236204bff916a141d04": "lGukPN", "f71b4dde2ab3b4275d2e3dc9a29a4653": "ZAbM6C", "f75013ce7eaae6139df1dd53a0a806ed": "FfLkj6", "f755fca9aa0b596f98a902e57e5767b0": "DVQD7U", "f817f334bbc43eee589f09a9dffb9672": "Ji6DYE", "f86e7c90924c89e1ef8a737b790d8772": "So5ImR", "f8aebf6fbc9ed779e91322883a6c9ce8": "KPXGZv", "f95717bfd81aa8dbc1513245bd67b6be": "JsJhRc", "f988886470331dccc8ec086c41bfafcd": "qoy8RA", "fb0d24855ffc4243b6a41e589b18c4e6": "Z126q1", "fb1ff2e786a4652ecfc68ef8c2c0ccf6": "yUyUuR", "fb6c8751fc9b79c47afc93aebf47aff4": "qLMImy", "fbc62d204161e3c27b475cd977d46688": "Vl9zVp", "fc617ccb710cd555d877583d15733901": "jLrzeh", "fd246e1a3a16f8a50d7e273e0827d375": "eWsDPZ", "fd3fe8e362644375bfb459d621bcf60e": "m8nPse", "fd9e3814c8d16a302143959ebcd226c8": "fdiaxj", "fdb6d5e83df4c2f4c14210268df3f908": "qrkDAq", "fdf631eb0ab4787c4db7332bdf1ce7ca": "cB1u9Q", "fe53b89d88460c2372e88b9d4930f3f9": "Hp0Fhu", "fe80894d19ad6b77f0cf218b220af953": "7ivBcg", "fe8437a27fbaf6d3514cc22ebeadfde2": "fUgN3u", "fecd58c28b1044cb1e0d2da8daeec0e9": "hdqDUd", "ff1c83271cc1fafb48d86af42236cfb1": "VQNEMo", "ff853f821b142f6b2ff3304ac875c220": "PRDuAM"}
\ No newline at end of file
diff --git a/languages/cprogs/.idea/.gitignore b/languages/cprogs/.idea/.gitignore
new file mode 100644
index 00000000..8bf4d45d
--- /dev/null
+++ b/languages/cprogs/.idea/.gitignore
@@ -0,0 +1,6 @@
+# Default ignored files
+/shelf/
+/workspace.xml
+# Datasource local storage ignored files
+/dataSources/
+/dataSources.local.xml
diff --git a/languages/cprogs/.idea/cprogs.iml b/languages/cprogs/.idea/cprogs.iml
new file mode 100644
index 00000000..f08604bb
--- /dev/null
+++ b/languages/cprogs/.idea/cprogs.iml
@@ -0,0 +1,2 @@
+
+
\ No newline at end of file
diff --git a/languages/cprogs/.idea/misc.xml b/languages/cprogs/.idea/misc.xml
new file mode 100644
index 00000000..79b3c948
--- /dev/null
+++ b/languages/cprogs/.idea/misc.xml
@@ -0,0 +1,4 @@
+
+
+
+
\ No newline at end of file
diff --git a/languages/cprogs/.idea/modules.xml b/languages/cprogs/.idea/modules.xml
new file mode 100644
index 00000000..02c2a389
--- /dev/null
+++ b/languages/cprogs/.idea/modules.xml
@@ -0,0 +1,8 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/languages/cprogs/.idea/vcs.xml b/languages/cprogs/.idea/vcs.xml
new file mode 100644
index 00000000..b2bdec2d
--- /dev/null
+++ b/languages/cprogs/.idea/vcs.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/languages/cprogs/CMakeLists.txt b/languages/cprogs/CMakeLists.txt
deleted file mode 100644
index 4915b8ca..00000000
--- a/languages/cprogs/CMakeLists.txt
+++ /dev/null
@@ -1,7 +0,0 @@
-cmake_minimum_required(VERSION 3.6)
-project(learntosolveit)
-
-set(CMAKE_C_STANDARD 11)
-
-set(SOURCE_FILES Ex_1.14_Hist_Freq.c)
-add_executable(learntosolveit ${SOURCE_FILES})
\ No newline at end of file
diff --git a/languages/cprogs/Ex_1.10_TbsBlnkSpaces.c b/languages/cprogs/Ex_1.10_TbsBlnkSpaces.c
index 2c59024e..e06534e3 100644
--- a/languages/cprogs/Ex_1.10_TbsBlnkSpaces.c
+++ b/languages/cprogs/Ex_1.10_TbsBlnkSpaces.c
@@ -7,11 +7,22 @@
#include
+const char *input = "This\tis\ta\b\btest\tstring.";
+int input_index = 0;
+
+int _getchar(void) {
+ if (input[input_index] == '\0') {
+ return EOF;
+ } else {
+ return input[input_index++];
+ }
+}
+
int main(void)
{
int c;
- while((c = getchar()) != EOF)
+ while((c = _getchar()) != EOF)
{
if(c == '\t')
{
diff --git a/languages/cprogs/Ex_1.12_word_per_line.c b/languages/cprogs/Ex_1.12_word_per_line.c
index 2955fc22..6d1e081f 100644
--- a/languages/cprogs/Ex_1.12_word_per_line.c
+++ b/languages/cprogs/Ex_1.12_word_per_line.c
@@ -4,24 +4,28 @@
*
* */
+// concept is: do nothing if you meet more than 1 blankspaces or tab spaces or newlines or "anti word characters"
+
#include
-#define IN 1
-#define OUT 0
-/* This program counts the number of lines, characters and words */
-int main (int argc, char *argv[]) {
- int c,state;
- state = IN;
- while((c=getchar()) != EOF) {
- if(c==' ' || c == '\t')
- state=OUT;
- else if (state == OUT) {
- state=IN;
+#define CTRL(x) (x & 0x1f)
+
+int main()
+{
+ int c;
+
+ while((c = getchar()) != EOF && c != CTRL('d') )
+ {
+ if(c == ' ' || c == '\t' || c == '\n' || c == '-')
+ {
putchar('\n');
- putchar(c);
+ while((c = getchar()) == ' ' || c == '\t' || c == '\n' || c == '-' )
+ {
+ ; //do nothing // we could actually skip the braces and just enter ; after closing the while's condition brackets
+ }
}
- else
- putchar(c);
+ putchar(c);
}
-}
\ No newline at end of file
+}
+
diff --git a/languages/cprogs/Ex_1.16_LongLine.c b/languages/cprogs/Ex_1.16_LongLine.c
index a147f2f6..01e19ed0 100644
--- a/languages/cprogs/Ex_1.16_LongLine.c
+++ b/languages/cprogs/Ex_1.16_LongLine.c
@@ -1,63 +1,100 @@
/**
* Exercise 1.16
*
- * Write a Program to print the longest line input
- *
+ * Write a program to print the length of an arbitrarily long input line
+ * and as much text as possible
+ *
**/
-#include
-#define MAXLINE 1000
+#include
+
+/* The size of the output that we would like */
+#define MAX 1000
+
+/* define our functions*/
+int getNewLine(char line[], int max);
+void copy(char to[], char from[]);
+
+int main(){
-int mgetline(char line[],int lim);
+ int len, max;
+ char line[MAX];
+ char longest[MAX];
-void copy(char to[],char from[]);
+ max = 0;
+ while((len = getNewLine(line, MAX)) > 0){
+ if(len > max){
-int main(void)
-{
- int len,max;
- char line[MAXLINE], maxline[MAXLINE];
+ max = len;
+ copy(longest, line);
- max =0;
+ }
+
+ }
+
+ if (max > 0){
- while((len = mgetline(line, MAXLINE)) > 0)
- {
- if(len > max)
- {
- max = len;
- copy(maxline,line);
- }
- }
+ printf("length = %i, string=%s", max, longest);
+
+ }
+
+ return 0;
- if(max>0)
- printf("%s",maxline);
}
-
-int mgetline(char s[],int lim)
-{
- int i,c;
+/* get a line in a character array */
+int getNewLine(char arr[], int lim){
+
+ int c, i;
+
+ for(i=0; i < lim -1 && (c=getchar()) != EOF && c != '\n'; ++i){
+
+ arr[i] = c;
+
+ }
+ if(c == '\n'){
- for(i=0;i
+#include
-int main() {
+const char *input = "This\tis\ta\ttest\\string\bwith\ttabs\\and\\backspaces.\n\nnewline";
+int input_index = 0;
- int char_count, num_lines, num_tabs, num_spaces;
+int _getchar(void) {
+ if (input[input_index] == '\0') {
+ return EOF;
+ } else {
+ return input[input_index++];
+ }
+}
+int main()
+{
+ int c, blanks, tabs, newlines;
- num_lines = 0;
- num_tabs = 0;
- num_spaces = 0;
+ blanks = tabs = newlines = 0;
- while ((char_count = getchar()) != EOF) {
- if (char_count == '\n')
- ++num_lines;
- if (char_count == '\t')
- ++num_tabs;
- if (char_count == ' ')
- ++num_spaces;
+ while ((c = _getchar()) != EOF) {
+ if (c == ' ')
+ ++blanks;
+ if (c == '\t')
+ ++tabs;
+ if (c == '\n')
+ ++newlines;
}
- printf("Blanks: %d\nTabs: %d\nNewlines: %d\n", num_spaces, num_tabs, num_lines);
-
+ printf("Blanks: %d\n", blanks);
+ printf("Tabs: %d\n", tabs);
+ printf("Newlines: %d\n", newlines);
}
diff --git a/languages/cprogs/Ex_1.9_SinBlank.c b/languages/cprogs/Ex_1.9_SinBlank.c
index 28551142..b04acd53 100644
--- a/languages/cprogs/Ex_1.9_SinBlank.c
+++ b/languages/cprogs/Ex_1.9_SinBlank.c
@@ -6,6 +6,19 @@
#include
+const char *input = "This line has many blanks to be replaced by single blank";
+int input_index = 0;
+
+int custom_getchar(void) {
+ if (input[input_index] == '\0') {
+ return EOF;
+ } else {
+ return input[input_index++];
+ }
+}
+
+
+
#define NONBLANK '-'
int main(void)
@@ -14,7 +27,7 @@ int main(void)
lastc = NONBLANK;
- while((c = getchar()) != EOF)
+ while((c = custom_getchar()) != EOF)
{
if(c == ' ')
{
diff --git a/languages/cprogs/Ex_2.1_cal_limits.c b/languages/cprogs/Ex_2.1_cal_limits.c
index 876be392..309e265f 100644
--- a/languages/cprogs/Ex_2.1_cal_limits.c
+++ b/languages/cprogs/Ex_2.1_cal_limits.c
@@ -14,15 +14,15 @@
* () casting it the required type again
*/
-#include
-#include
-#include
+#include
+#include
+#include
-int main(void)
+int main()
{
/* ranges of various floating-point types through calculation */
printf("Ranges of various floating-point types through calculation:\n");
-
+
printf("Minimum Signed Char %d\n",-(char)((unsigned char) ~0 >> 1) - 1);
printf("Maximum Signed Char %d\n",(char) ((unsigned char) ~0 >> 1));
@@ -41,28 +41,27 @@ int main(void)
printf("Maximum Unsigned Short %d\n",(unsigned short)~0);
printf("Maximum Unsigned Int %u\n",(unsigned int)~0);
printf("Maximum Unsigned Long %lu\n\n",(unsigned long)~0);
-
+
/* ranges of various floating-point types from standard headers */
printf("Ranges of various floating-point types from standard headers:\n");
-
printf("Minimum Signed Char %d\n", SCHAR_MIN);
- printf("Maximum Signed Char %d\n", SCHAR_MAX);
-
- printf("Minimum Signed Short %d\n", SHRT_MIN);
- printf("Maximum Signed Short %d\n", SHRT_MAX);
-
- printf("Minimum Signed Int %d\n", INT_MIN);
- printf("Maximum Signed Int %d\n", INT_MAX);
-
- printf("Minimum Signed Long %ld\n", LONG_MIN);
- printf("Maximum signed Long %ld\n", LONG_MAX);
-
- /* Unsigned Maximum Values */
-
- printf("Maximum Unsigned Char %d\n", UCHAR_MAX);
- printf("Maximum Unsigned Short %d\n", USHRT_MAX);
- printf("Maximum Unsigned Int %u\n", UINT_MAX);
- printf("Maximum Unsigned Long %lu\n", ULONG_MAX);
-
+ printf("Maximum Signed Char %d\n", SCHAR_MAX);
+
+ printf("Minimum Signed Short %d\n", SHRT_MIN);
+ printf("Maximum Signed Short %d\n", SHRT_MAX);
+
+ printf("Minimum Signed Int %d\n", INT_MIN);
+ printf("Maximum Signed Int %d\n", INT_MAX);
+
+ printf("Minimum Signed Long %ld\n", LONG_MIN);
+ printf("Maximum signed Long %ld\n", LONG_MAX);
+
+ /* Unsigned Maximum Values */
+
+ printf("Maximum Unsigned Char %d\n", UCHAR_MAX);
+ printf("Maximum Unsigned Short %d\n", USHRT_MAX);
+ printf("Maximum Unsigned Int %u\n", UINT_MAX);
+ printf("Maximum Unsigned Long %lu\n", ULONG_MAX);
+
return 0;
}
diff --git a/languages/cprogs/Ex_2.5_any.c b/languages/cprogs/Ex_2.5_any.c
index 67084e7f..07059088 100644
--- a/languages/cprogs/Ex_2.5_any.c
+++ b/languages/cprogs/Ex_2.5_any.c
@@ -45,28 +45,21 @@ int mgetline(char s[],int lim)
s[i]='\0';
}
+
int any(char s1[],char s2[])
{
- int i,j,check_next_char;
-
- check_next_char=1;
+ int i,j;
- for(i=0;s1[i]!='\0'&& (check_next_char);)
+ for(i=0;s1[i]!='\0';++i)
{
// iterate through s2 while trying to find matching character from s1
- for(j=0;s2[j]!='\0'&& (s1[i]!=s2[j]);++j)
+ for(j=0;(s1[i]!=s2[j]) && s2[j]!='\0';++j)
; // continue
- if(s2[j]=='\0') {
- check_next_char=1;
- i++; // go for the next char in s1
+ if(s2[j]!='\0' && s2[j] != '\n') { // check that s2 [j]! = '\n', since s1 and s2 both have the character '\n' in the penultimate position of the string.
+ return i;
}
- else
- check_next_char=0; // match found
}
- if(s1[i]=='\0')
- return -1;
- else
- return i;
-}
+ return -1;
+}
\ No newline at end of file
diff --git a/languages/cprogs/Ex_4.13_reverse_string.c b/languages/cprogs/Ex_4.13_reverse_string.c
index 37cb5ebb..ce7c8c31 100644
--- a/languages/cprogs/Ex_4.13_reverse_string.c
+++ b/languages/cprogs/Ex_4.13_reverse_string.c
@@ -34,28 +34,36 @@ int mgetline(char s[],int lim)
s[i]='\0';
}
-void reverse(char s[])
-{
- void reverser(char s[],int i,int len);
-
- reverser(s,0,strlen(s));
+void reverse(char s[]){
+
+ static int i = 0;
+ static int len;
+
+ int j;
+ char c;
+
+ if (i ==0){
+ len= strlen(s);
+ }
+
+ j= len - (i+1);
+
+ if (i
-#include
-#include
+#include
+#include
+#include
+#include
+
+
+#define BUFSIZE 100
#define MAXOP 100
+#define MAXVAL 100
#define NUMBER '0'
-int getop(char []);
+int getop(char[]);
void push(double);
double pop(void);
+int getch(void);
+void ungetch(int);
-/* reverse polish calculator */
-
-int main(void)
-{
- int type;
- double op2;
- char s[MAXOP];
-
- while((type = getop(s)) != EOF)
- {
- switch(type)
- {
- case NUMBER:
- push(atof(s));
- break;
- case '+':
- push(pop()+pop());
- break;
- case '*':
- push(pop()*pop());
- break;
- case '-':
- op2 = pop();
- push(pop()-op2);
- break;
- case '/':
- op2 = pop();
- if(op2 != 0.0)
- push(pop()/op2);
- else
- printf("error:zero divisor\n");
- break;
- case '%':
- op2 = pop();
- if(op2 != 0.0)
- push(fmod(pop(),op2));
- else
- printf("erro:zero divisor\n");
- break;
- case '\n':
- printf("\t%.8g\n",pop());
- break;
- default:
- printf("error: unknown command %s\n",s);
- break;
-
- }
- }
- return 0;
-}
-
-
-#define MAXVAL 100
-
+int bufp = 0;
int sp = 0;
+char buf[BUFSIZE];
+
double val[MAXVAL];
-void push(double f)
-{
- if(sp < MAXVAL)
- val[sp++]=f;
- else
- printf("error:stack full, cant push %g\n",f);
+void push(double f) {
+ if (sp < MAXVAL)
+ val[sp++] = f;
+ else
+ printf("error:stack full, cant push %g\n", f);
}
-
-double pop(void)
-{
- if(sp>0)
- return val[--sp];
- else
- {
- printf("error: stack empty\n");
- return 0.0;
- }
+double pop(void) {
+ if (sp > 0)
+ return val[--sp];
+ else {
+ printf("error: stack empty\n");
+ return 0.0;
+ }
}
-#include
-
-int getch(void);
-void ungetch(int);
-
int getop(char s[]) {
- int i, c;
- while ((s[0] = c = getch()) == ' ' || c == '\t')
- ;
- s[1] = '\0';
- if (!isdigit(c) && c != '.' && c != '-')
- return c; // not a number
- i = 0;
- if (c == '-' || isdigit(c)) // collect integer part along with '-'
- while (isdigit(s[++i] = c = getch()))
- ;
- if (c == '.') // collect fraction part
- while (isdigit(s[++i] = c = getch()))
- ;
- s[i] = '\0';
- if (c != EOF)
- ungetch(c);
- if (strcmp(s, "-") == 0)
- return '-';
- return NUMBER;
+ int i, c;
+ while ((s[0] = c = getch()) == ' ' || c == '\t')
+ ;
+ s[1] = '\0';
+ if (!isdigit(c) && c != '.' && c != '-')
+ return c; // not a number
+ i = 0;
+ if (c == '-' || isdigit(c)) // collect integer part along with '-'
+ while (isdigit(s[++i] = c = getch()))
+ ;
+ if (c == '.') // collect fraction part
+ while (isdigit(s[++i] = c = getch()))
+ ;
+ s[i] = '\0';
+ if (c != EOF)
+ ungetch(c);
+ if (strcmp(s, "-") == 0)
+ return '-';
+ return NUMBER;
}
-#define BUFSIZE 100
-
-char buf[BUFSIZE];
-int bufp = 0;
+int getch(void) { return (bufp > 0) ? buf[--bufp] : getchar(); }
-int getch(void)
-{
- return (bufp > 0) ? buf[--bufp] : getchar();
+void ungetch(int c) {
+ if (bufp >= BUFSIZE)
+ printf("ungetch: too many characters\n");
+ else
+ buf[bufp++] = c;
}
-void ungetch(int c)
-{
- if(bufp >= BUFSIZE)
- printf("ungetch: too many characters\n");
- else
- buf[bufp++] = c;
+/* Reverse Polish Calculator */
+int main(void) {
+ int type;
+ double op2;
+ char s[MAXOP];
+
+ while ((type = getop(s)) != EOF) {
+ switch (type) {
+ case NUMBER:
+ push(atof(s));
+ break;
+ case '+':
+ push(pop() + pop());
+ break;
+ case '*':
+ push(pop() * pop());
+ break;
+ case '-':
+ op2 = pop();
+ push(pop() - op2);
+ break;
+ case '/':
+ op2 = pop();
+ if (op2 != 0.0)
+ push(pop() / op2);
+ else
+ printf("error:zero divisor\n");
+ break;
+ case '%':
+ op2 = pop();
+ if (op2 != 0.0)
+ push(fmod(pop(), op2));
+ else
+ printf("erro:zero divisor\n");
+ break;
+ case '\n':
+ printf("\t%.8g\n", pop());
+ break;
+ default:
+ printf("error: unknown command %s\n", s);
+ break;
+ }
+ }
+ return 0;
}
-
diff --git a/languages/cprogs/Ex_4.5_calculator_math_functions.c b/languages/cprogs/Ex_4.5_calculator_math_functions.c
index ac5acb41..36a5549e 100644
--- a/languages/cprogs/Ex_4.5_calculator_math_functions.c
+++ b/languages/cprogs/Ex_4.5_calculator_math_functions.c
@@ -151,7 +151,11 @@ int getop(char s[])
if(strlen(s)>1)
return NAME;
else
- return c;
+ /*return c; this line was bad since when s < 1, the array s only has one character s[0], therofore, this character must
+ be retorned in order to see if it is d,?,s etc. The character c instead contain whatever non-lower value wich always will result
+ in a command uknown*/
+
+ return s[0];
}
if(!isdigit(c) && c!='.' && c!='-')
diff --git a/languages/cprogs/Ex_5.14_sortrevnum.c b/languages/cprogs/Ex_5.14_sortrevnum.c
index fde3e4a1..897f865d 100644
--- a/languages/cprogs/Ex_5.14_sortrevnum.c
+++ b/languages/cprogs/Ex_5.14_sortrevnum.c
@@ -48,7 +48,7 @@ int main(int argc,char *argv[])
if(option & NUMERIC)
myqsort((void **)lineptr,0,nlines -1,(int (*)(void *,void *))numcmp);
else
- myqsort((void **)lineptr,0,nlines -1,(int (*)(void *,void *))numcmp);
+ myqsort((void **)lineptr,0,nlines -1,(int (*)(void *,void *))strcmp);
writelines(lineptr,nlines,option & DECR);
}
else
diff --git a/languages/cprogs/Ex_5.17_sortdfnr-withoption.c b/languages/cprogs/Ex_5.17_sortdfnr-withoption.c
index d4f7e269..d796e651 100644
--- a/languages/cprogs/Ex_5.17_sortdfnr-withoption.c
+++ b/languages/cprogs/Ex_5.17_sortdfnr-withoption.c
@@ -3,6 +3,7 @@
#include
#include
+#include
#define NUMERIC 1 /* numeric sort */
#define DECR 2 /* sort in decreasing order */
@@ -15,7 +16,7 @@ void error(char *);
int numcmp(char *,char *);
void readargs(int argc,char *argv[]);
int readlines(char *lineptr[],int maxlines);
-void mqsort(void *v[],int left,int right,int (*comp)(void *,void *));
+void myqsort(void *v[],int left,int right,int (*comp)(void *,void *));
void writelines(char *lineptr[],int nlines,int order);
int option = 0;
@@ -57,7 +58,6 @@ int main(int argc,char *argv[])
void readargs(int argc,char *argv[])
{
int c;
- int atoi(char *);
while(--argc > 0 && (c=(*++argv)[0])=='-' || c == '+')
{
@@ -177,7 +177,7 @@ void error(char *);
/* substr: get a substring of S and put in str */
-void substr(char *s,char *str)
+void substr(char *s,char *str, int maxstr)
{
int i,j,len;
extern int pos1,pos2;
@@ -258,7 +258,7 @@ int readlines(char *lineptr[],int maxlines)
}
/* writelines: write output lines */
-void writelines(char *lineptr[],int nlines)
+void writelines(char *lineptr[],int nlines, int order)
{
int i;
@@ -296,7 +296,7 @@ int mgetline(char s[],int lim)
{
int c,i;
- for(i=0;i
#include
#include
-enum { NAME,PARENS,BRACKETS };
-enum { NO, YES };
+#define MAXTOKEN 100
+
+enum {NAME,PARENS,BRACKETS};
+enum { NO, YES};
void dcl(void);
void dirdcl(void);
void errmsg(char *);
int gettoken(void);
-extern int tokentype; /* type of last token */
-extern char token[]; /* last token string */
-extern char name[]; /* identifier name */
-extern char out[];
+int tokentype; /* type of last token */
+char token[MAXTOKEN]; /* last token string */
+char name[MAXTOKEN]; /* identifier name */
+char out[1000];
+char datatype[MAXTOKEN];
extern int prevtoken;
+extern int tokentype;
+extern char token[];
+int prevtoken = NO;
-
-/* dcl: parse a declarator */
-void dcl(void)
-{
- int ns;
-
- for(ns = 0; gettoken() == '*';) /* count *'s */
- ns++;
-
- dirdcl();
-
- while(ns-- > 0)
- strcat(out,"pointer to");
-}
-
-
-/* dirdcl: parse a direct declaration */
-void dirdcl(void)
+int main(void)
{
- int type;
-
- if(tokentype == '(' )
- {
- dcl();
-
- if(tokentype != ')')
- errmsg("error: missing ) \n");
+ int i;
+
+ if(gettoken()!=EOF)
+ {
+ strcpy(datatype,token);
+ out[0]='\0';
+ dcl();
+
+ if(tokentype != '\n')
+ printf("syntax error \n");
+
+ printf(" %s %s %s \n",name,out,datatype);
+ for(i=0;i
-#include
+/* dcl: parse a declarator */
-/* enum { NAME,PARENS,BRACKETS}; */
-/* enum { NO,YES }; */
-
-extern int tokentype; /* type of last token */
-extern char token[]; /* last token string */
-int prevtoken = NO;
-
-/* gettoken : return next token */
-
-int gettoken(void)
+void dcl(void)
{
- int c,getch(void);
- void ungetch(int);
+ int ns;
- char *p = token;
-
- if(prevtoken == YES)
- {
- prevtoken = NO;
-
- return tokentype;
- }
+ for(ns=0;gettoken()=='*';) /* count *'s */
+ ns++;
- while((c=getch()) == ' ' || c == '\t')
- ;
+ dirdcl();
+ while(ns-- > 0)
+ strcat(out," pointer to");
+}
- if(c == '(')
- {
- if((c = getch()) == ')')
- {
- strcpy(token,"()");
- return tokentype = PARENS;
- }
- else
- {
- ungetch(c);
- return tokentype = '(';
- }
- }
- else if (c == '[')
- {
- for(*p++ = c; ( *p++ = getch()) != ']';)
- ;
- *p ='\0';
+/* dirdcl: parse a direct declarator */
- return tokentype = BRACKETS;
- }
- else if (isalpha(c))
- {
- for(*p++ = c; isalnum(c=getch()); )
- *p++ = c;
-
- *p = '\0';
-
- ungetch(c);
- return tokentype = NAME;
- }
- else
- return tokentype = c;
+void dirdcl(void)
+{
+ int type;
+
+ if(tokentype == '(') /* dcl */
+ {
+ dcl();
+
+ if(tokentype != ')')
+ errmsg("error: missing ) \n");
+ }
+ else if(tokentype == NAME) /* variable name */
+ strcpy(name,token);
+ else
+ errmsg("error: expected name or (dcl) \n");
+
+ while((type=gettoken()) == PARENS || type == BRACKETS )
+ if((type = PARENS))
+ strcat(out,"function returning");
+ else
+ {
+ strcat(out," arg");
+ strcat(out,token);
+ strcat(out," of");
+ }
}
-#define BUFSIZE 100
+void errmsg(char *msg)
+{
+ printf("%s", msg);
+ prevtoken = YES;
+}
+#define BUFSIZE 100
-char buf[BUFSIZE]; /* buffer for ungetch */
-int bufp = 0; /* next free position in buf */
+char buf[BUFSIZE]; /* buffer for ungetch */
+int bufp = 0; /* next free position in buf */
-int getch(void) /* get a (possibly pushed back) character */
+int getch(void) /* get a (possibly pushed back) character */
{
- return (bufp > 0) ? buf[--bufp]: getchar();
+ return (bufp > 0) ? buf[--bufp]:getchar();
}
-void ungetch(int c)
+void ungetch(int c) /* push a character back on input */
{
- if ( bufp >= BUFSIZE)
- printf("ungetch: too many characters \n");
- else
- buf[bufp++] = c;
+ if(bufp >= BUFSIZE)
+ printf("ungetch: too many characters \n");
+ else
+ buf[bufp++] = c;
}
-
diff --git a/languages/cprogs/Ex_5.1_getint.c b/languages/cprogs/Ex_5.1_getint.c
index de97f9ff..e80f1cda 100644
--- a/languages/cprogs/Ex_5.1_getint.c
+++ b/languages/cprogs/Ex_5.1_getint.c
@@ -59,11 +59,9 @@ int getint(int *pn)
int main(void)
{
- int n,s,array[SIZE],getint(int *);
+ int n,s,array[SIZE];
- for(n=0;n=0;n--)
- printf("%f",array[n]);
-
+ {
+ for(;n>=0;n--)
+ printf("%f\n",array[n]);
+ }
return 0;
}
diff --git a/languages/cprogs/Ex_5.4_strend.c b/languages/cprogs/Ex_5.4_strend.c
index c093df10..8c042840 100644
--- a/languages/cprogs/Ex_5.4_strend.c
+++ b/languages/cprogs/Ex_5.4_strend.c
@@ -1,4 +1,5 @@
#include
+
#define MAXLINE 1000
int mgetline(char s[],int max);
diff --git a/languages/cprogs/Ex_5.5_strncpy.c b/languages/cprogs/Ex_5.5_strncpy.c
index f75719f2..342f6089 100644
--- a/languages/cprogs/Ex_5.5_strncpy.c
+++ b/languages/cprogs/Ex_5.5_strncpy.c
@@ -18,7 +18,7 @@ void mystrncpy(char *, char *, int);
void mystrncat(char *, char *, char *, int);
int mystrncmp(char *, char *, int);
-int mystrlen(char *s);
+int mystrnlen(char *s);
int main(int argc, char *argv[])
{
@@ -77,7 +77,7 @@ void mystrncpy(char *dest,char *source,int n)
int extra = mystrnlen(dest) - n;
while (extra-- > 0) {
- *dest++;
+ dest++;
}
*dest = '\0';
diff --git a/languages/cprogs/Ex_5.7_readlines_using_array.c b/languages/cprogs/Ex_5.7_readlines_using_array.c
index 11417f62..eedaf555 100644
--- a/languages/cprogs/Ex_5.7_readlines_using_array.c
+++ b/languages/cprogs/Ex_5.7_readlines_using_array.c
@@ -43,9 +43,10 @@ int readlines(char *lineptr[],char *linestor,int maxlines)
char line[MAXLEN];
char *p = linestor;
char *linestop = linestor + MAXSTOR;
+ char c;
nlines=0;
-
+loop:
while((len=mgetline(line,MAXLEN)) > 0)
if(nlines >= maxlines || p+len > linestop)
return -1;
@@ -55,8 +56,14 @@ int readlines(char *lineptr[],char *linestor,int maxlines)
strcpy(p,line);
lineptr[nlines++]=p;
p+=len;
+ printf("get a newline? 0 for no, ENTER to input next line.");
+ c = getchar();
+ if(c != '0')
+ goto loop;
+ else if(c == '0')
+ return nlines;
}
- return nlines;
+ return 0;
}
/* writelines: write output lines */
@@ -128,4 +135,3 @@ int mgetline(char *s,int lim)
return s-t;
}
-
diff --git a/languages/cprogs/Ex_5.8_day_date.c b/languages/cprogs/Ex_5.8_day_date.c
index e552647c..a5fa6336 100644
--- a/languages/cprogs/Ex_5.8_day_date.c
+++ b/languages/cprogs/Ex_5.8_day_date.c
@@ -1,3 +1,6 @@
+/*
+ * Error check in day_of_year and month_day
+ */
#include
static char daytab[2][13]={
@@ -6,15 +9,24 @@ static char daytab[2][13]={
};
int day_of_year(int year,int month,int day);
-void month_day(int year,int yearday);
+void month_day(int year,int yearday, int *month, int *day);
int main(void)
{
- int day,mo,dat;
+ int yearday,month,day;
+
+ yearday=day_of_year(1988,2,29);
+ printf("%d\n", yearday);
+
+ yearday=day_of_year(2020,2,31);
+ printf("%d\n", yearday);
+
+ month_day(1988,60, &month, &day);
+ printf("Month: %d, Day: %d\n", month, day);
+
+ month_day(1999,366, &month, &day);
+ printf("Month: %d, Day: %d\n", month, day);
- day=day_of_year(1988,2,29);
- printf("%d\n",day);
- month_day(1988,60);
return 0;
}
@@ -25,6 +37,9 @@ int day_of_year(int year,int month,int day)
int i,leap;
leap = year % 4 == 0 && year%100 != 0 || year%400 == 0;
+
+ if(year < 1 || month < 1 || month > 12 || day < 1 || day > daytab[leap][month])
+ return -1;
for(i=1;i (leap? 366 : 365))
+ {
+ *month = -1;
+ *day = -1;
+ return;
+ }
+
for(i=1;yearday > daytab[leap][i];i++)
yearday -= daytab[leap][i];
- printf("Month: %d, Day: %d\n", i, yearday);
-
+ *month = i;
+ *day = yearday;
}
-
diff --git a/languages/cprogs/Ex_6.3.c b/languages/cprogs/Ex_6.3.c
index 6d648b6d..ee0dd3e1 100644
--- a/languages/cprogs/Ex_6.3.c
+++ b/languages/cprogs/Ex_6.3.c
@@ -1,316 +1,249 @@
/*
- * Write a cross-referencer that prints a list of all words in a document, and for each word, a list of the line numbers
- * on which it occurs. Remove noise words like "the" and "and" so on.
+ * Write a cross-referencer that prints a list of all words in a document,
+ * and for each word, a list of the line numbers on which it occurs.
+ * Remove noise words like "the" and "and" so on.
*
*/
-
/*
- * 1. Add all the word structures (word structure will have word and line numbers to the tree.
- * 2. A word can occur in more than one line, if the same word is found and the new line number to the line numbers.
- * 3. So line numbers should be a linked list of numbers.
- * 4. Print it.
+ * 1. Create a binary tree that will contain words and structure with lines on which words occur.
+ * 2. Check if the word is noisy with binary search.
+ * 3. Print the words and lines.
* */
+#define N_OF_NOISEWORDS 123
+
+const char *noiseWords[N_OF_NOISEWORDS]={"a", "about", "after", "all",
+"also", "an", "another", "any", "are", "as", "and", "at", "be",
+"because", "been", "before", "being", "between", "but", "both",
+"by", "came", "can", "come", "could","did", "do","each", "even",
+"for", "from", "further", "furthermore","get", "got","has", "had",
+"he", "have", "her", "here", "him", "himself", "his", "how", "hi",
+"however","i", "if", "in", "into", "is", "it", "its", "indeed","just",
+"like","made", "many", "me", "might", "more", "moreover", "most",
+"much","must", "my","never", "not", "now","of", "on", "only", "other",
+"our", "out", "or", "over","said", "same", "see", "should", "since",
+"she", "some", "still", "such","take", "than", "that", "the", "their",
+"them", "then", "there", "these", "therefore", "they", "this", "those",
+"through", "to", "too", "thus","under", "up","very","was", "way", "we",
+"well", "were", "what", "when", "where", "which", "while", "who",
+"will", "with", "would","you", "your"};
#include
-#include
#include
+#include
#include
-#include
-#define MAXWORD 1000 /* longest word that can be read by mgetword */
-#define DEFAULT_COMP_LEN 8 /* default length to compare */
+#define MAXWORD 500
-/*
- * tnode: Tree node from K&R2 page 140. Words are initially read into
- * the tree by getword.
- */
-struct tnode
-{
- char *word;
- int count;
- struct linenumber *linenumbers;
- struct tnode *left;
- struct tnode *right;
-};
-
-struct linenumber {
- int *number;
- struct linenumber *nextnumber;
-};
+ struct tnode{
+ char *word;
+ unsigned int count;
+ struct ocurLine *lineOfOccurence;
-/*
- * simroot: Part of a linked list of pointers to simword lists with
- * a common root.
- */
-struct simroot
-{
- struct simword *firstword; /* points to the list of words */
- struct simroot *nextroot; /* points to the next node in the list */
-};
+ struct tnode *left;
+ struct tnode *right;
+ };
-/*
- * simword: Part of a linked list of words with a common root. Points
- * to the word in the tnodes.
- */
-struct simword
-{
- char *word; /* points to the word in the tree */
- int count; /* copied from the tree */
- int linenumber; /* copied from the tree */
- struct simword *nextword; /* next node */
-};
-
-struct tnode *addtree(struct tnode *, char *, int);
-void treeprint(const struct tnode *);
-int mgetword(char *, int, int *);
-struct linenumber *lnumberalloc(void);
-struct linenumber *addlinenumber(struct linenumber *, int);
-
-int main(int argc, char *argv[])
-{
- struct tnode *root;
- char word[MAXWORD];
- int len;
- int lineno = 0;
-
-
- /* get all the words */
- root = NULL;
- while(mgetword(word, MAXWORD, &lineno) != 'x')
- if(isalpha(word[0]))
- root = addtree(root, word, lineno);
-
- if(argc == 1)
- len = DEFAULT_COMP_LEN;
- else if(argc == 2)
- len = atoi(argv[1]);
- else {
- printf("Incorrect number of arguments.\n");
- return 1;
- }
-
- printf("Words with line numbers\n");
- treeprint(root); /* prints all the words */
+ struct ocurLine{
+ unsigned int line;
+ struct ocurLine *next;
+ };
- return 0;
-} /* end of main() */
+int binarySearch(const char *arr[], int l, int r, char *x);
-struct tnode *talloc(void);
-char *mstrdup(char *);
+void treeprint(const struct tnode *p);
+char *mstrdup(char *s);
-/* mgetword from Ex6.1 */
+int getWord(char *word, int lim);
-#define IN 1
-#define OUT 0
+void ungetch(char c);
+int getch(void);
-int mgetword(char *word, int lim, int *lineno_addr)
-{
- int c, d, getch(void), comment, string, directive;
- void ungetch(int);
- char *w = word;
+char buf; /* buffer for getch/ungetch */
- comment = string = directive = OUT;
-
- while (isspace(c = getch())) {
- if (c == '\n') {
-
- *lineno_addr = *lineno_addr +1;
+struct tnode *talloc(void);
+struct tnode *addtree(struct tnode *p, char *w, unsigned int l);
- }
- }
+void printline(const struct ocurLine *p);
- /* Check if inside a comment */
+struct ocurLine *linealloc(void);
+struct ocurLine *addLine(struct ocurLine *p, unsigned int l);
- if (c == '/') {
- if ((d = getch()) == '*') {
- comment = IN;
- } else {
- comment = OUT;
- ungetch(d);
- }
- }
+int main()
+{
+ int l=1;
+ struct tnode *root;
+ char word[MAXWORD];
+
+ root = NULL;
+
+ while(getWord(word, MAXWORD) != EOF)
+ if (word[0] == '\n') // Adding 1 to [l] if there is new line
+ l++;
+ else if(isalpha(word[0]))
+ if (binarySearch(noiseWords, 0, N_OF_NOISEWORDS, word) == -1)
+ root = addtree(root, word, l);
+ treeprint(root);
+}
- /* Check if inside a quote */
- if ( c == '\"') {
- string = IN;
- }
+ /* Binary search for our array of noise words. */
+int binarySearch(const char *arr[], int l, int r, char *x)
+{
+ if (r >= l) {
+ int mid = l + (r - l) / 2;
+ int cmp = strcmp(arr[mid], x);
- /* Check if inside a directive */
+ if (cmp == 0)
+ return mid;
- if (c == '#') {
- directive = IN;
- }
+ if (cmp > 0)
+ return binarySearch(arr, l, mid - 1, x);
+
+ return binarySearch(arr, mid + 1, r, x);
+ }
+
+ return -1;
+}
- if ( c == '\\') {
- c = getch(); /* ignore the \\ character */
- }
- if (comment == OUT && string == OUT && directive == OUT) {
+int getWord(char *word, int lim)
+{
+ int c;
- if (c != EOF)
- *w++ = c;
+ char *w = word;
- if (!isalnum(c) && c !='_' ) {
- *w = '\0';
- return c;
- }
+ while (isspace(c = getch()) && c != '\n')
+ ;
- for ( ; --lim > 0; w++) {
- *w = getch();
- if (!isalnum(*w) && *w != '_') {
- ungetch(*w);
- break;
- }
- }
- *w = '\0';
- return word[0];
- }
- else if ( comment == IN) {
+ if (c != EOF)
*w++ = c;
- *w++ = d;
-
- while ((*w++ = c = getch())) {
- if ( c == '*' ) {
- if ( (c = getch()) == '/' ) {
- *w++ = c;
- comment = OUT;
- break;
- } else {
- ungetch(c);
- }
- }
- }
- *w = '\0';
- }
- else if ( string == IN) {
- *w++ = c;
- while ((*w++ = getch()) != '\"') {
- if ( *w == '\\') /* Take care of escaped quotes */
- *w++ = getch();
- }
- string = OUT;
- *w = '\0';
- }
- else if (directive == IN) {
- *w++ = c;
- while ((*w++ = getch()) != '\n') {
- if ( c == '\\') { /* Take care of continuation line escape */
- *w++ = getch();
- }
- }
- directive = OUT;
+ if (!isalpha(c) && c != '_' && c != '#') {
*w = '\0';
+ return c;
}
- return c;
+ for ( ; --lim > 0; w++)
+ if (!isalnum(*w = getch())){
+ ungetch(*w);
+ break;
+ }
+ *w = '\0';
+ return word[0];
}
-
-
-/***************************************************************************
- * All code below here is from K&R2. *
- ***************************************************************************/
-
-/*
- * addtree: From K&R2 page 141.
- * Adds a node containing w, at or below node p.
- */
-struct tnode *addtree(struct tnode *p, char *w, int linenumber)
+/* addtree: adds branch to a tree*/
+struct tnode *addtree(struct tnode *p, char *w, unsigned int l)
{
int cond;
if(p == NULL) { /* new word */
p = talloc();
- p->word = mstrdup(w);
+ p->word=mstrdup(w);
p->count = 1;
- p->linenumbers = NULL;
- p->linenumbers = addlinenumber(p->linenumbers, linenumber);
+ p->lineOfOccurence = NULL;
+ p->lineOfOccurence = addLine(p->lineOfOccurence, l);
p->left = p->right = NULL;
}
- else if((cond = strcmp(w, p->word)) == 0) {
- p->count++;
- p->linenumbers = addlinenumber(p->linenumbers, linenumber);
+ else if((cond = strcmp(w, p->word)) == 0){
+ p->count++;
+ p->lineOfOccurence = addLine(p->lineOfOccurence, l);
}
else if(cond < 0)
- p->left = addtree(p->left, w, linenumber);
+ p->left = addtree(p->left, w, l);
else
- p->right = addtree(p->right, w, linenumber);
+ p->right = addtree(p->right, w, l);
return p;
}
-struct linenumber *addlinenumber(struct linenumber *p, int linenumber) {
- if (p == NULL) {
- p = lnumberalloc();
- p->number = linenumber;
- p->nextnumber = NULL;
- } else {
- p->nextnumber = addlinenumber(p->nextnumber, linenumber);
- }
+/* treeprint: prints all the branches of the tree with words.*/
+void treeprint(const struct tnode *p)
+{
- return p;
+ if(p != NULL) {
+ treeprint(p->left);
+
+ printf("%s: [", p->word);
+
+ printline(p->lineOfOccurence);
+
+ printf("]\n");
+
+ treeprint(p->right);
+ }
}
-struct linenumber *lnumberalloc(void)
+/* talloc: From K&R2 page 142. Makes a tnode. */
+struct tnode *talloc(void)
{
- return (struct linenumber *) malloc(sizeof(struct linenumber));
+ return (struct tnode *) malloc(sizeof(struct tnode));
}
-/* treeprint: From K&R2 page 142. Prints tree p in-order. */
-void treeprint(const struct tnode *p)
+
+/* printline: Prints all lines.*/
+void printline(const struct ocurLine *p)
{
- if(p != NULL) {
- treeprint(p->left);
- printf("\n%s :", p->word);
- printnumbers(p->linenumbers);
- treeprint(p->right);
+ if (p->next == NULL)
+ printf("%i", p->line);
+ else{
+ printf("%i, ", p->line);
+ printline(p->next);
}
}
-void printnumbers(const struct linenumber *p) {
- if (p != NULL) {
- printf("%d,", p->number);
- printnumbers(p->nextnumber);
+/* addLine: adds a line to word. */
+struct ocurLine *addLine(struct ocurLine *p, unsigned int l)
+{
+ if (p == NULL){
+ p = linealloc();
+ p->line = l;
+ p->next = NULL;
}
+ else
+ p->next = addLine(p->next, l);
+ return p;
}
-/* talloc: From K&R2 page 142. Makes a tnode. */
-struct tnode *talloc(void)
+/* linealloc: Makes ocurLine*/
+struct ocurLine *linealloc(void)
{
- return (struct tnode *) malloc(sizeof(struct tnode));
+ return (struct ocurLine *) malloc(sizeof(struct ocurLine));
}
/* strdup: From K&R2 page 143. Makes a duplicate of s. */
char *mstrdup(char *s)
{
char *p;
+
p = (char *) malloc(strlen(s) + 1);
+
if(p != NULL)
strcpy(p, s);
return p;
}
-/*
- * getch and ungetch are from K&R2, page 79
- */
-#define BUFSIZE 100
-
-char buf[BUFSIZE]; /* buffer for ungetch() */
-int bufp = 0; /* next free position in buf */
+/*************************************************************
+ * Getch/Ungetch functions from previous exercises *
+ *************************************************************/
-int getch(void) { /* get a (possibly pushed back) character */
- return (bufp > 0) ? buf[--bufp] : getchar();
+/* getch: gets a (possibly pushed-back) character */
+int getch(void)
+{
+ if (buf > 0){
+ int copy=buf;
+ buf=0;
+ return copy;
+ }
+ else
+ return getchar();
}
-void ungetch(int c) { /* push character back on input */
- if(bufp >= BUFSIZE)
- printf("ungetch: too many characters\n");
- else
- buf[bufp++] = c;
- return;
-}
\ No newline at end of file
+/* ungetch: pushes character back on input */
+void ungetch(char c)
+{
+ buf = c;
+}
diff --git a/languages/cprogs/Ex_6.4.c b/languages/cprogs/Ex_6.4.c
index dcfe33bb..2e383d11 100644
--- a/languages/cprogs/Ex_6.4.c
+++ b/languages/cprogs/Ex_6.4.c
@@ -15,12 +15,8 @@
#include
#include
-#define MAXWORD 1000 /* longest word that can be read by mgetword */
+#define MAXWORD 1000
-/*
- * tnode: Tree node from K&R2 page 140. Words are initially read into
- * the tree by getword.
- */
struct tnode
{
char *word;
@@ -29,12 +25,12 @@ struct tnode
struct tnode *right;
};
-struct numwordnode
+struct bynumbernode
{
int number;
- struct words *wordslist;
- struct numwordnode *left;
- struct numwordnode *right;
+ struct words *wordlist;
+ struct bynumbernode *left;
+ struct bynumbernode *right;
};
struct words
@@ -43,229 +39,158 @@ struct words
struct words *nextword;
};
-struct tnode *addtree(struct tnode *, char *);
-struct numwordnode *addnumtree(struct numwordnode *, int, char*);
+struct tnode *addtree(struct tnode *p, char *w);
+struct bynumbernode *addnumtree(struct bynumbernode *, int, char*);
struct words *addwordtolist(struct words*, char *);
void printwords(const struct words*, const int);
-struct numwordnode *traverse(const struct tnode *, struct numwordnode *);
-void treeprint(const struct numwordnode *);
+struct bynumbernode *traverse(const struct tnode *, struct bynumbernode *);
+void treeprint(const struct bynumbernode *);
int mgetword(char *, int);
-int main(int argc, char *argv[])
-{
- struct tnode *root;
- struct numwordnode *numwordroot;
+struct tnode *talloc(void){
+ return (struct tnode *)malloc(sizeof(struct tnode));
+};
- char word[MAXWORD];
+struct bynumbernode *bynumbernodealloc(void){
+ return (struct bynumbernode *)malloc(sizeof(struct bynumbernode));
+};
- /* get all the words */
- root = NULL;
- numwordroot = NULL;
+struct words *wordsalloc(void){
+ return (struct words *)malloc(sizeof(struct words));
+};
- while(mgetword(word, MAXWORD) != 'x')
- if(isalpha(word[0]))
- root = addtree(root, word);
- numwordroot = traverse(root, numwordroot);
- printf("Words and their frequencies:\n");
+#define BUFSIZE 100
- treeprint(numwordroot);
+char buf[BUFSIZE];
+int bufp=0;
- return 0;
+int getch(void){
+ return (bufp > 0) ? buf[--bufp] : getchar();
}
-
-struct tnode *talloc(void);
-struct numwordnode *numwordalloc(void);
-struct words *wordsalloc(void);
-char *mstrdup(char *);
-
-/* mgetword from Ex6.1 */
-
-#define IN 1
-#define OUT 0
-
-
-
-int mgetword(char *word, int lim)
-{
- int c, d, getch(void), comment, string, directive;
- void ungetch(int);
- char *w = word;
-
- comment = string = directive = OUT;
-
- while (isspace(c = getch()))
- ;
-
- /* Check if inside a comment */
-
- if (c == '/') {
- if ((d = getch()) == '*') {
- comment = IN;
- } else {
- comment = OUT;
- ungetch(d);
- }
- }
-
- /* Check if inside a quote */
-
- if ( c == '\"') {
- string = IN;
+void ungetch(int c){
+ if(bufp >= BUFSIZE){
+ printf("ungetch: too many characters\n");
}
+ else buf[bufp++] = c;
+ return;
+}
- /* Check if inside a directive */
-
- if (c == '#') {
- directive = IN;
+char *mstrdup(char *s){
+ char *p;
+ p = (char *)malloc(strlen(s) + 1);
+ if(p != NULL){
+ strcpy(p, s);
}
+ return p;
+}
- if ( c == '\\') {
- c = getch(); /* ignore the \\ character */
- }
- if (comment == OUT && string == OUT && directive == OUT) {
- if (c != EOF)
- *w++ = c;
+int getword(char *word, int lim){
+ int c, getch(void);
+ void ungetch(int);
+ char *w = word;
- if (!isalnum(c) && c !='_' ) {
- *w = '\0';
- return c;
- }
+ while(isspace(c = getch()) || c == '_' || c == '/' || c == '#' || c == '*' || c == '"');
- for ( ; --lim > 0; w++) {
- *w = getch();
- if (!isalnum(*w) && *w != '_') {
- ungetch(*w);
- break;
- }
- }
- *w = '\0';
- return word[0];
- }
- else if ( comment == IN) {
+ if(c != EOF){
*w++ = c;
- *w++ = d;
-
- while ((*w++ = c = getch())) {
- if ( c == '*' ) {
- if ( (c = getch()) == '/' ) {
- *w++ = c;
- comment = OUT;
- break;
- } else {
- ungetch(c);
- }
- }
- }
- *w = '\0';
-
}
- else if ( string == IN) {
- *w++ = c;
- while ((*w++ = getch()) != '\"') {
- if ( *w == '\\') /* Take care of escaped quotes */
- *w++ = getch();
- }
- string = OUT;
+ if(!isalpha(c)){
*w = '\0';
+ return c;
}
- else if (directive == IN) {
- *w++ = c;
- while ((*w++ = getch()) != '\n') {
- if ( c == '\\') { /* Take care of continuation line escape */
- *w++ = getch();
- }
+ for( ; --lim > 0; w++){
+ if(!isalnum(*w = getch())){
+ ungetch(*w);
+ break;
}
- directive = OUT;
- *w = '\0';
}
-
- return c;
-
+ *w = '\0';
+ return word[0];
}
-
-
-
-/***************************************************************************
- * All code below here is from K&R2. *
- ***************************************************************************/
-
-/*
- * addtree: From K&R2 page 141.
- * Adds a node containing w, at or below node p.
- */
+/* addtree : add a node with w at or below p */
struct tnode *addtree(struct tnode *p, char *w)
{
int cond;
- if(p == NULL) { /* new word */
- p = talloc();
+ if (p == NULL){ /* new word */
+ p = talloc(); // make new node
p->word = mstrdup(w);
p->count = 1;
p->left = p->right = NULL;
}
- else if((cond = strcmp(w, p->word)) == 0)
+ else if ((cond = strcmp(w, p->word)) == 0){
p->count++;
- else if(cond < 0)
+ }
+ else if(cond < 0){
p->left = addtree(p->left, w);
- else
+ }
+ else{
p->right = addtree(p->right, w);
+ }
return p;
}
+// treeprint: in-order print of tree p
+void treeprint(const struct bynumbernode *p){
+ if(p != NULL){
+ treeprint(p->left);
+ printwords(p->wordlist, p->number);
+ treeprint(p->right);
+ }
+}
-struct numwordnode *addnumtree(struct numwordnode *p, int count, char* w)
+void printwords(const struct words* w, const int count)
{
- if (p == NULL) {
- p = numwordalloc();
- p->number = count;
- p->wordslist = NULL;
- p->wordslist = addwordtolist(p->wordslist, w);
+ if (w != NULL){
+ printf("%d->%s", count, w->word);
+ w = w->nextword;
}
- else if (count < p->number)
- p->left = addnumtree(p->left, count, w);
- else
- p->right = addnumtree(p->right, count, w);
- return p;
+ while (w != NULL) {
+ printf(", %s", w->word);
+ w = w->nextword;
+ }
+ printf("\n");
}
-struct words *addwordtolist(struct words* list, char *w)
-{
- if (list == NULL) {
+
+struct words *addwordtolist(struct words* list, char *w){
+ if(list == NULL){
list = wordsalloc();
list->word = mstrdup(w);
list->nextword = NULL;
- } else {
+ }
+ else {
list->nextword = addwordtolist(list->nextword, w);
}
return list;
}
-/* treeprint: From K&R2 page 142. Prints tree p in-order. */
-void treeprint(const struct numwordnode *p)
-{
- if(p != NULL) {
- treeprint(p->left);
- printwords(p->wordslist, p->number);
- treeprint(p->right);
- }
-}
-void printwords(const struct words* w, const int count)
-{
- if (w != NULL) {
- printf("%s->%d\n", w->word, count);
- w = w->nextword;
+struct bynumbernode *addnumtree(struct bynumbernode *n, int i, char *w){
+ if (n == NULL){
+ n = bynumbernodealloc();
+ n->number = i;
+ n->wordlist = NULL;
+ n->wordlist = addwordtolist(n->wordlist, w);
+ }
+ else if (n->number == i){
+ addwordtolist(n->wordlist, w);
+ }
+ else if (n->number < i){
+ n->left = addnumtree(n->left, i, w);
+ }
+ else{
+ n->right = addnumtree(n->right, i, w);
}
+ return n;
}
-struct numwordnode *traverse(const struct tnode *p, struct numwordnode *q)
-{
-
- if (p != NULL) {
+struct bynumbernode *traverse(const struct tnode *p, struct bynumbernode *q){
+ if(p != NULL){
q = traverse(p->left, q);
q = addnumtree(q, p->count, p->word);
q = traverse(p->right, q);
@@ -273,48 +198,30 @@ struct numwordnode *traverse(const struct tnode *p, struct numwordnode *q)
return q;
}
-/* talloc: From K&R2 page 142. Makes a tnode. */
-struct tnode *talloc(void)
-{
- return (struct tnode *) malloc(sizeof(struct tnode));
-}
-
-struct numwordnode *numwordalloc(void)
-{
- return (struct numwordnode *) malloc(sizeof(struct numwordnode));
-}
+int main(){
+ struct tnode *root;
+ char word[MAXWORD];
+
+ struct bynumbernode *nroot;
-struct words *wordsalloc(void) {
- return (struct words *) malloc(sizeof(struct words));
-}
+ root = NULL;
+ nroot = NULL;
+ while(getword(word, MAXWORD) != EOF){
+ if(isalpha(word[0])){
+ root = addtree(root, word);
+ }
+ }
+
+ nroot = traverse(root, nroot);
-/* strdup: From K&R2 page 143. Makes a duplicate of s. */
-char *mstrdup(char *s)
-{
- char *p;
- p = (char *) malloc(strlen(s) + 1);
- if(p != NULL)
- strcpy(p, s);
- return p;
+ printf("Words by frequency:\n");
+
+ treeprint(nroot);
+ return 0;
}
-/*
- * getch and ungetch are from K&R2, page 79
- */
-#define BUFSIZE 100
-char buf[BUFSIZE]; /* buffer for ungetch() */
-int bufp = 0; /* next free position in buf */
-int getch(void) { /* get a (possibly pushed back) character */
- return (bufp > 0) ? buf[--bufp] : getchar();
-}
-void ungetch(int c) { /* push character back on input */
- if(bufp >= BUFSIZE)
- printf("ungetch: too many characters\n");
- else
- buf[bufp++] = c;
- return;
-}
+
diff --git a/languages/cprogs/Ex_7.1_lower-upper.c b/languages/cprogs/Ex_7.1_lower-upper.c
index 5ef30604..847780de 100644
--- a/languages/cprogs/Ex_7.1_lower-upper.c
+++ b/languages/cprogs/Ex_7.1_lower-upper.c
@@ -1,24 +1,35 @@
-/* Write a program which converts upper case to lower case or lower case to
+/* Write a program which converts upper case to lower case or lower case to
upper case depending on the name it is involved with as found in argv[0] */
-#include
-#include
-#include
+#include
+#include
+#include
/* lower: converts upper case to lower case */
/* upper: converts lower case to upper case */
-int main(int argc,char *argv[])
-{
- int c;
+const char *input = "This\tis\ta\ttest";
+int input_index = 0;
- if(strcmp(argv[0],"./lower")==0)
- while((c=getchar()) != EOF)
- putchar(tolower(c));
- else
- while((c=getchar()) != EOF)
- putchar(toupper(c));
-
- return 0;
+int _getchar(void) {
+ if (input[input_index] == '\0') {
+ return EOF;
+ } else {
+ return input[input_index++];
+ }
}
+
+
+int main(int argc, char *argv[]) {
+ int c;
+
+ if (strcmp(argv[0], "./lower") == 0)
+ while ((c = _getchar()) != EOF)
+ putchar(tolower(c));
+ else
+ while ((c = _getchar()) != EOF)
+ putchar(toupper(c));
+
+ return 0;
+}
diff --git a/languages/cprogs/Ex_7.3_minprintf.c b/languages/cprogs/Ex_7.3_minprintf.c
index d1b3b32e..f6bbeb19 100644
--- a/languages/cprogs/Ex_7.3_minprintf.c
+++ b/languages/cprogs/Ex_7.3_minprintf.c
@@ -6,7 +6,12 @@ int main(void)
{
char *a="Hello,World";
minprintf("%s",a);
-
+ int i = 10;
+ minprintf("%d\n", i);
+ int b = 011;
+ minprintf("b in octal: %o, and in decimal: %d\n", b, b);
+ int h = 10;
+ minprintf("h in hex: %x, and in decimal: %d\n", h, h);
return 0;
}
@@ -39,8 +44,16 @@ void minprintf(char *fmt,...)
break;
case 's':
for(sval = va_arg(ap,char *);*sval;sval++)
- putchar(*sval);
+ putchar(*sval);
break;
+ case 'o':
+ ival = va_arg(ap,int);
+ printf("%o", ival);
+ break;
+ case 'x':
+ ival =va_arg(ap,int);
+ printf("%x", ival);
+ break;
default:
putchar(*p);
break;
diff --git a/languages/cprogs/Ex_7.4.c b/languages/cprogs/Ex_7.4.c
index ca392bf6..3d1224b7 100644
--- a/languages/cprogs/Ex_7.4.c
+++ b/languages/cprogs/Ex_7.4.c
@@ -1,53 +1,74 @@
-/*
- *
- * Write a private version of scanf analogous to minprintf from the
- * previous section.
- *
- */
-
+/* minscanf: minimalistic scanf function */
#include
-void minprintf(char *fmt,...);
+#include
+void minscanf(char *fmt,...);
int main(void)
{
- char *a="Hello,World";
- minprintf("%s",a);
-
+
+ int i;
+ minscanf("%d", &i);
+ printf("minscanf input: %d\n", i);
+
+ char * a;
+ minscanf("%s", a);
+ printf("minscanf input: %s\n", a);
+
+ float f;
+ minscanf("%f", &f);
+ printf("minscanf input: %f\n", f);
+
+ int o;
+ minscanf("%o", &o);
+ printf("minscanf input in octal %o, in decimal %d\n", o, o);
+
+ int x;
+ minscanf("%x", &x);
+ printf("minscanf input in hex %x, in decimal %d\n", x, x);
return 0;
}
-/* TODO: Convert to scanf */
-
-void minprintf(char *fmt,...)
+void minscanf(char *fmt,...)
{
va_list ap; /* points to each unnamed arg in turn */
char *p,*sval;
- int ival;
- double dval;
+ int *ival;
+ float *dval;
va_start(ap,fmt); /* make ap point to 1st unnamed arg */
-
+
for(p=fmt;*p;p++)
{
if(*p != '%')
{
- putchar(*p);
continue;
}
switch(*++p)
{
case 'd':
- ival = va_arg(ap,int);
- printf("%d",ival);
+ ival = va_arg(ap,int*);
+ char * d = "44";
+ sscanf(d,"%d",ival);
break;
case 'f':
- dval = va_arg(ap,double);
- printf("%f",dval);
+ dval = va_arg(ap,float*);
+ char * f = "5.33";
+ sscanf(f,"%f",dval);
break;
case 's':
- for(sval = va_arg(ap,char *);*sval;sval++)
- putchar(*sval);
+ sval = va_arg(ap,char*);
+ sscanf("test char", "%s", sval);
+ break;
+ case 'o':
+ ival = va_arg(ap,int*);
+ char * o = "011";
+ sscanf(o, "%o", ival);
+ break;
+ case 'x':
+ ival =va_arg(ap,int*);
+ char * x = "1a";
+ sscanf(x, "%x", ival);
break;
default:
putchar(*p);
diff --git a/languages/cprogs/Ex_7.4v2.c b/languages/cprogs/Ex_7.4v2.c
new file mode 100644
index 00000000..d3b5bac4
--- /dev/null
+++ b/languages/cprogs/Ex_7.4v2.c
@@ -0,0 +1,43 @@
+#include
+#include
+#include
+//compare two files, printing the first line where they differ
+int main(int argc, char *argv[]){
+ FILE *fp1, *fp2;
+ void filecmp(FILE *, FILE *);
+ char *prog = argv[0];
+ if(argc == 3){
+ if((fp1 = fopen(argv[1], "r")) ==NULL || (fp2 = fopen(argv[2], "r")) ==NULL){
+ fprintf(stderr, "%s: can't open %s\n", prog, argv[1]);
+ exit(1);
+ }
+ else{
+ filecmp(fp1, fp2);
+ fclose(fp1);
+ fclose(fp2);
+ }
+ }
+ else{
+ printf("%s", "Please enter two file names");
+ }
+ exit(0);
+}
+
+void filecmp(FILE *f1, FILE *f2){
+ size_t size = 100;
+ char *string;
+ char *string1;
+
+ while(!feof(f1) && !feof(f2)){
+ string = (char *) malloc(size);
+ getline(&string, &size, f1);
+ string1 = (char *) malloc(size);
+ getline(&string1, &size, f2);
+ if(strcmp(string, string1)!= 0)
+ {
+ printf("%s", string);
+ printf("%s", string1);
+ return;
+ }
+ }
+}
diff --git a/languages/cprogs/Fibonacci.c b/languages/cprogs/Fibonacci.c
deleted file mode 100644
index e1ba9c67..00000000
--- a/languages/cprogs/Fibonacci.c
+++ /dev/null
@@ -1,30 +0,0 @@
-/* Fibonacci Numbers Generator */
-/* Fibonacci series is formed by adding the latest two numbers to get the next one,starting from 0 and 1 */
-
-#include
-
-int main(void)
-{
- int first,second,next,limit;
- printf("How many Numbers in the Series?");
- scanf("%d",&limit);
-
- first=0;
- second=1;
-
- printf("%d,%d",first,second);
-
- while(limit > 2) /* 0 and 1 are default and counted */
- {
- next = first + second;
- printf(",%d",next);
-
- first= second;
- second = next;
-
- --limit;
- }
-return 0;
-}
-
-
diff --git a/languages/cprogs/Nofbtn.c b/languages/cprogs/Nofbtn.c
deleted file mode 100644
index 54b77e0b..00000000
--- a/languages/cprogs/Nofbtn.c
+++ /dev/null
@@ -1,24 +0,0 @@
-/* Write a Program to Count Blanks, Tabs and Newlines */
-
-#include
-
-int main(void)
-{
- int nb,nt,nl,c;
-
- nb=nt=nl=0;
-
- while((c=getchar())!=EOF)
- {
- if(c==' ')
- ++nb;
- if(c=='\t')
- ++nt;
- if(c=='\n')
- ++nl;
- }
- printf("No. of Blanks is %d,No. of Tabs is %d and No. of Newlines is %d",nb,nt,nl);
-
-return 0;
-}
-
diff --git a/languages/cprogs/alloc_afree.c b/languages/cprogs/alloc_afree.c
deleted file mode 100644
index 31cf373c..00000000
--- a/languages/cprogs/alloc_afree.c
+++ /dev/null
@@ -1,38 +0,0 @@
-#define ALLOCSIZE 1000 /* size of available space */
-
-static char allocbuf[ALLOCSIZE]; /* storage for alloc */
-static char *allocp = allocbuf; /* next free position */
-
-char *alloc(int n) /* return pointer to n characters */
-{
- if( allocbuf + ALLOCSIZE - allocp >= n)
- {
- allocp += n;
- return allocp - n; /* old p */
- }
- else
- return 0;
-}
-
-
-void afree(char *p) /* free storage pointed to by p */
-{
- if(p >= allocbuf && p < allocbuf + ALLOCSIZE)
- allocp = p;
-}
-
-int main(void)
-{
- char *p;
- printf("%p\n",allocp);
-
- p=alloc(100);
- printf("%p\n",allocp);
-
- afree(p);
- printf("%p\n",allocp);
-
- return 0;
-}
-
-
diff --git a/languages/cprogs/anylonglinelen.c b/languages/cprogs/anylonglinelen.c
deleted file mode 100644
index d55e45e6..00000000
--- a/languages/cprogs/anylonglinelen.c
+++ /dev/null
@@ -1,62 +0,0 @@
-/* Program to print the longest line.
- This program prints the length of any-length line with as much possible text it can hold */
-
-#include
-
-#define MAXLINE 1000
-
-int getline(char line[],int lim);
-void copy(char to[],char from[]);
-
-int main(void)
-{
- int len,max;
- char line[MAXLINE],maxline[MAXLINE];
-
- max = 0;
-
- while((len=getline(line,MAXLINE)) > 0)
- {
- printf("%d\t%s",len,line);
- if(len > max)
- {
- max=len;
- copy(maxline,line);
- }
- }
- printf("%s",maxline);
-
-return 0;
-}
-
-int getline(char s[],int lim)
-{
- int i,j,c;
-
- for(i=0,j=0;(c=getchar())!=EOF && c!= '\n';++i)
- if( i < lim-2 )
- {
- s[i] = c;
- ++j;
- }
- if( c == '\n')
- {
- s[i] = c;
- ++i;
- ++j;
- }
- s[j] = '\0';
-
- return i;
-}
-
-void copy(char to[],char from[])
-{
- int i;
-
- i=0;
-
- while((to[i]=from[i]) != '\0')
- ++i;
-}
-
diff --git a/languages/cprogs/atoiv2.c b/languages/cprogs/atoiv2.c
deleted file mode 100644
index 978afcdf..00000000
--- a/languages/cprogs/atoiv2.c
+++ /dev/null
@@ -1,34 +0,0 @@
-/* Ex5.6 */
-
-#include
-#include
-int atoiv2(char *);
-
-int main(void)
-{
- char *s="1234";
- int ret;
-
- ret=atoiv2(s);
-
- printf("%d",ret);
-
- return 0;
-}
-
-int atoiv2(char *s)
-{
- int n,sign;
-
- for(;isspace(*s);s++) /* skip white space */
- ;
- sign = ( *s =='-')? -1:1;
-
- if(*s=='+' || *s=='-')
- s++;
- for(n=0;isdigit(*s);s++)
- n = 10 *n + *s - '0';
-
- return sign * n;
-}
-
diff --git a/languages/cprogs/binsearch.c b/languages/cprogs/binsearch.c
deleted file mode 100644
index 87beeaf6..00000000
--- a/languages/cprogs/binsearch.c
+++ /dev/null
@@ -1,36 +0,0 @@
-/* binsearch: Implementation of Binary Search,In the array v[],search for n in the binary way*/
-
-#include
-
-int binsearch(int x,int v[],int n);
-
-int main(void)
-{
- int arr[]={2,4,5,7,8,9,11,23,45,50};
- int x,n;
-
- printf("%d",binsearch(9,arr,10));
-
- return 0;
-}
-
-int binsearch(int x,int v[],int n)
-{
- int low,high,mid;
-
- low=0;
- high=n-1;
-
- while(low v[mid])
- low = mid + 1;
- else
- return mid;
- }
- return -1;
-}
diff --git a/languages/cprogs/bitcount.c b/languages/cprogs/bitcount.c
deleted file mode 100644
index fb9616ff..00000000
--- a/languages/cprogs/bitcount.c
+++ /dev/null
@@ -1,22 +0,0 @@
-/* bitcount : count 1 bits in x */
-#include
-
-int bitcount(unsigned x);
-
-int main(void)
-{
- printf("%d",bitcount((unsigned)255));
-
- return 0;
-}
-
-int bitcount(unsigned x)
-{
- int b;
-
- for(b=0; x!= 0; x >>=1)
- if( x & 01)
- b++;
- return b;
-}
-
diff --git a/languages/cprogs/counts.c b/languages/cprogs/counts.c
deleted file mode 100644
index c8005243..00000000
--- a/languages/cprogs/counts.c
+++ /dev/null
@@ -1,41 +0,0 @@
-/* Program to count the digits,white spaces and others */
-
-#include
-
-int main(void)
-{
- int c,i,nwhite,nother,ndigit[10];
-
- nwhite=nother=0;
-
- for(i=0;i<10;i++)
- ndigit[i]=0;
-
- while((c=getchar())!=EOF)
- {
-
- switch(c)
- {
- case '0':case '1':case '2':case '3':case '4':case '5':case '6':case '7':case '8':case '9':
- ndigit[c-'0']++;
- break;
- case ' ':
- case '\t':
- case '\n':
- nwhite++;
- break;
- default:
- nother++;
- break;
-
- }
- }
-
- printf("digits =");
- for(i=0;i<10;i++)
- printf("%d",ndigit[i]);
- printf(", white space = %d, other = %d \n",nwhite,nother);
-
- return 0;
-}
-
diff --git a/languages/cprogs/day_datev3.c b/languages/cprogs/day_datev3.c
deleted file mode 100644
index 76c07ca2..00000000
--- a/languages/cprogs/day_datev3.c
+++ /dev/null
@@ -1,55 +0,0 @@
-#include
-
-static char daytab[2][13] = {
- {0,31,28,31,30,31,30,31,31,30,31,30,31},
- {0,31,29,31,30,31,30,31,31,30,31,30,31}
-};
-
-int day_of_year(int year,int month,int day);
-void month_day(int year,int yearday,int *pmonth,int *pday);
-
-int main(void)
-{
- int day,dat,mon;
-
- day=day_of_year(1981,10,2);
- printf("%d\n",day);
-
- month_day(1981,252,&mon,&dat);
- printf("%d,%d",mon,dat);
-
- return 0;
-}
-
-/* day_of_year: set day of year from month and day */
-int day_of_year(int year,int month,int day)
-{
- int leap;
- char *p;
-
- leap = year%4 == 0 && year % 100 !=0 || year %400 == 0;
- p = daytab[leap];
-
- while(--month)
- day += *++p;
- return day;
-}
-
-/* month_day: set month, day from day of year */
-void month_day(int year,int yearday,int *pmonth,int *pday)
-{
- int leap;
- char *p;
-
- leap = year%4 == 0 && year %100 !=0 || year % 400 == 0;
-
- p = daytab[leap];
-
- while(yearday > *++p)
- yearday -= *p;
-
- *pmonth = p - *(daytab + leap);
- *pday = yearday;
-}
-
-
diff --git a/languages/cprogs/dcl.c b/languages/cprogs/dcl.c
deleted file mode 100644
index 41724bb7..00000000
--- a/languages/cprogs/dcl.c
+++ /dev/null
@@ -1,159 +0,0 @@
-/* DCL: A Recursive Descent Parser */
-
-/* dcl: parse a declarator */
-
-void dcl(void)
-{
- int ns;
-
- for(ns=0;gettoken()=='*';) /* count *'s */
- ns++;
-
- dirdcl();
- while(ns-- > 0)
- strcat(out,"pointer to");
-}
-
-/* dirdcl: parse a direct declarator */
-
-void dirdcl(void)
-{
- int type;
-
- if(tokentype == '(') /* dcl */
- {
- dcl();
-
- if(tokentype != ')')
- printf("error: missing ) \n");
- }
- else if(tokentype == NAME) /* variable name */
- strcpy(name,token);
- else
- printf("error: expected name or (dcl) \n");
-
- while((type=gettoken()) == PARENS || type == BRACKETS )
- if(type = PARENS)
- strcat(out,"function returning");
- else
- {
- strcat(out,"arg");
- strcat(out,token);
- strcat(out,"of");
- }
-}
-
-
-#include
-#include
-#include
-
-#define MAXTOKEN 100
-
-enum {NAME,PARENS,BRACKETS};
-
-void dcl(void);
-void directdcl(void);
-int gettoken(void);
-int tokentype; /* type of last token */
-char token[MAXTOKEN]; /* last token string */
-char name[MAXTOKEN]; /* identifier name */
-char datatype[MAXTOKEN]; /* data type=char, int etc */
-char out[1000]; /* output string */
-
-int main(void)
-{
- while(gettoken()!=EOF)
- {
- strcpy(datatype,token);
- out[0]='\0';
- dcl();
-
- if(tokentype != '\n')
- printf("syntax error \n");
-
- printf(" %s %s %s \n",name,out,datatype);
- }
-
-return 0;
-}
-
-int gettoken(void)
-{
- int i,getch(void);
- void ungetch(int);
- char *p = token;
-
- while((c=getch()) == ' ' || c == '\t')
- ;
-
- if( c == '(')
- {
- if((c=getch()) == ')')
- {
- strcpy(token,"()");
- return tokentype = PARENS;
- }
- else
- {
- ungetch(c);
- return tokentype = '(';
- }
- else if ( c == '[')
- {
- for(*p++ = c; (*p++ = getch()) != ']';)
- ;
- *p = '\0';
- return tokentype = BRACKETS;
- }
- else if ( isalpha(c))
- {
- for(*p++ =c; isalnum(c=getch());)
- *p++ = c;
- *p = '\0';
- ungetch(c);
- return tokentype = NAME;
- }
- else
- return tokentype =c;
-}
-
-#define BUFSIZE 100
-
-char buf[BUFSIZE]; /* buffer for ungetch */
-int bufp = 0; /* next free position in buf */
-
-int getch(void) /* get a (possibly pushed back) character */
-{
- return (bufp > 0) ? buf[--bufp]:getchar();
-}
-
-void ungetch(int c) /* push a character back on input */
-{
- if(bufp >= BUFSIZE)
- printf("ungetch: too many characters \n");
- else
- buf[bufp++] = c;
-}
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/languages/cprogs/endian.c b/languages/cprogs/endian.c
deleted file mode 100644
index c0b7559d..00000000
--- a/languages/cprogs/endian.c
+++ /dev/null
@@ -1,11 +0,0 @@
-#include
-int main(int argc, char *argv[])
-{
- int a=0x99000011;
- unsigned char *c = (unsigned char *) (&a);
- if (*c == 0x11)
- printf("little endian\n");
- else
- printf("big endian\n");
-
-}
diff --git a/languages/cprogs/eratosthenes.c b/languages/cprogs/eratosthenes.c
deleted file mode 100644
index 5d6ade03..00000000
--- a/languages/cprogs/eratosthenes.c
+++ /dev/null
@@ -1,31 +0,0 @@
-/**
- * Program illustrating sieve of Eratosthenes.
- *
- **/
-
-#include
-
-#define N 100
-
-int main(int argc, char *argv[]) {
- int nums[N];
-
- for (int i = 2; i < N; ++i) {
- nums[i] = i;
- }
-
- for (int i = 2; i < N; ++i) {
- for (int j = i; j < N; ++j) {
- if (i != j && nums[j] != 0 && (nums[j] % i == 0)) {
- nums[j] = 0;
- }
- }
- }
-
- for (int k = 2; k < N; ++k) {
- if (nums[k] != 0) {
- printf("%d\n", nums[k]);
- }
- }
-
-}
diff --git a/languages/cprogs/fork1.c b/languages/cprogs/fork1.c
deleted file mode 100644
index d9dd8723..00000000
--- a/languages/cprogs/fork1.c
+++ /dev/null
@@ -1,8 +0,0 @@
-#include
-
-int main()
-{
- int pid;
- pid = fork();
- printf("%d \n",pid);
-}
diff --git a/languages/cprogs/fsize.c b/languages/cprogs/fsize.c
deleted file mode 100644
index 977b7dba..00000000
--- a/languages/cprogs/fsize.c
+++ /dev/null
@@ -1,133 +0,0 @@
-/* Print File Sizes */
-#include
-#include
-#include /* flags for read and write */
-#include /* typedefs */
-#include /* structure returned by stat */
-#include "dirent.h"
-
-void fsize(char *);
-
-/* print file sizes */
-int main(int argc,char **argv)
-{
- if(argc == 1) /* default : current directory */
- fsize(".");
- else
- while(--argc > 0)
- fsize(*++argv);
- return 0;
-}
-
-int stat(char *,struct stat *);
-void dirwalk(char *,void (*fcn)(char *));
-
-/* fsize: print size of file "name" */
-void fsize(char *name)
-{
- struct stat stbuf;
-
- if(stat(name,&stbuf) == -1)
- {
- fprintf(stderr,"fsize: Can't access %s \n",name);
- return;
- }
- if((stbuf.st_mode & S_IFMT) == S_IFDIR)
- dirwalk(name,fsize);
- printf("%8ld %s \n",stbuf.st_size,name);
-}
-
-
-#define MAX_PATH 1024
-
-/* dirwalk: apply fcn to all files in dir */
-void dirwalk(char *dir,void (*fcn)(char *))
-{
- char name[MAX_PATH];
- Dirent *dp;
- DIR *dfd;
-
- if((dfd = opendir(dir)) == NULL)
- {
- fprintf(stderr,"dirwalk: can't open %s\n",dir);
- return;
- }
-
- while((dp = readdir(dfd)) != NULL)
- {
- if(strcmp(dp->name,".") == 0 || strcmp(dp->name,"..") == 0)
- continue;
- if(strlen(dir)+strlen(dp->name)+2 > sizeof(name))
- fprintf(stderr,"dirwalk: name %s/ %s too long \n",dir,dp->name);
- else
- {
- sprintf(name,"%s/%s",dir,dp->name);
- (*fcn)(name);
- }
- }
- closeddir(dfd);
-}
-
-
-#ifndef DIRSIZ
-#define DIRSIZ 14
-#endif
-
-struct direct /* directory entry */
-{
- ino_t d_ino; /* inode number */
- char d_name[DIRSIZ]; /* long name does not have '\0' */
-};
-
-int fstat(int fd,struct stat *);
-
-/* opendir: open a directory for readdir calls */
-
-DIR *opendir(char *dirname)
-{
- int fd;
- struct stat stbuf;
- DIR *dp;
-
- if((fd = open(dirname,O_RDONLY,0)) == -1
- || fstat(fd,&stbuf) == -1
- || (stbuf.st_mode & S_IFMT) != S_IFDIR
- || (dp = (DIR *)malloc(sizeof(DIR))) == NULL)
- return NULL;
- dp->fd = fd;
- return dp;
-}
-
-/* closedir: close directory opened by opendir */
-void closedir(DIR *dp)
-{
- if(dp)
- {
- close(dp->fd);
- free(dp);
- }
-}
-
-
-#include /* local directory structure */
-/* readdir: read directory entries in sequence */
-
-Dirent *readdir(DIR *dp)
-{
- struct direct dirbuf; /* local directory structure */
- static Dirent d; /* return: portable structure */
-
- while(read(dp->fd,(char *)&dirbuf,sizeof(dirbuf)) == sizeof(dirbuf))
- {
- if(dirbuf.d_ino= 0)
- continue;
- d.ino = dirbuf.d_ino;
- strncpy(d.name,dirbuf.d_name,DIRSIZ);
- d.name[DIRSIZ] = '\0';
- return &d;
- }
-
- return NULL;
-}
-
-
diff --git a/languages/cprogs/getbits.c b/languages/cprogs/getbits.c
deleted file mode 100644
index aaa296ad..00000000
--- a/languages/cprogs/getbits.c
+++ /dev/null
@@ -1,17 +0,0 @@
-/* getbits: get n bits from the position p */
-
-#include
-
-unsigned getbits(unsigned x,int p,int n);
-
-int main(void)
-{
- printf("%u",getbits((unsigned)8,3,1));
-}
-
-unsigned getbits(unsigned x,int p,int n)
-{
- return (x >> (p+1-n)) & ~(~0 << n);
-}
-
-
diff --git a/languages/cprogs/getline_woandr.c b/languages/cprogs/getline_woandr.c
deleted file mode 100644
index 3bd85308..00000000
--- a/languages/cprogs/getline_woandr.c
+++ /dev/null
@@ -1,58 +0,0 @@
-/* Program demonstrates the former getline forloop without && and ||.
-Also demonstrates enum data type usage */
-
-#include
-#define MAXLINE 1000
-
-int getline(char line[],int maxline);
-
-int main(void)
-{
- char line[MAXLINE];
-
- getline(line,MAXLINE);
-
- printf("%s",line);
-
- return 0;
-}
-
-int getline(char s[],int lim)
-{
- int c,i;
- enum values{NO=0,YES};
- enum values proceed;
-
- proceed= YES;
-
- i =0;
-
- while(proceed == YES)
- {
- if( i > lim - 1)
- proceed = NO;
- else if((c=getchar()) == EOF)
- proceed = NO;
- else if( c == '\n')
- proceed = NO;
- else
- {
- s[i] = c;
- ++i;
- proceed = YES;
- }
- }
- if ( c == '\n')
- {
- s[i] = c;
- ++i;
- }
- s[i] = '\0';
-
- return i;
-}
-
-
-
-
-
diff --git a/languages/cprogs/getpass1.c b/languages/cprogs/getpass1.c
deleted file mode 100644
index af10935a..00000000
--- a/languages/cprogs/getpass1.c
+++ /dev/null
@@ -1,68 +0,0 @@
-#include
-#include
-#include
-#include
-#include
-
-static int gp_save_term(int fd, struct termios *tios)
-{
- return tcgetattr(fd, tios);
-}
-
-static int gp_load_term(int fd, struct termios *tios)
-{
- return tcsetattr(fd, TCSAFLUSH, tios);
-}
-
-static void gp_set_password_flags(struct termios *tios)
-{
- tios->c_lflag &= ~ECHO; /* disable echo */
- tios->c_lflag &= ~ISIG; /* ignore signals */
-}
-
-/* Get a password of max len-1 chars and store it in dest.
- * The string is anyway nul terminated, the echo disabled. */
-int palla_getpass(char *dest, size_t len)
-{
- unsigned int i; /* character index inside pass */
- int ttyfd = fileno(stdin);
- struct termios orig, new;
-
- /* sanity check */
- if (!len || !dest)
- return -1;
-
- /* Save the old status */
- if (gp_save_term(ttyfd, &orig) == -1)
- return -1;
- new = orig; /* copy it in the new */
- gp_set_password_flags(&new); /* set the right flags */
- if (gp_load_term(ttyfd, &new) == -1) /* load the new term config */
- return -1;
-
- /* Now we are in "password mode", get the input */
- i = 0;
- while(i < (len-1)) {
- char c;
- if (read(ttyfd, &c, 1) <= 0)
- break;
- if (c == '\n')
- break;
- dest[i] = c;
- i++;
- }
- dest[i] = '\0'; /* add the nul term */
- if (gp_load_term(ttyfd, &orig) == -1) /* restore the old term */
- return -1; /* sorry, the term is left unsane */
- return i;
-}
-
-int main(void)
-{
- char dest[10];
- printf("password: ");
- fflush(stdout);
- palla_getpass(dest, 10);
- printf("'%s'\n", dest);
- return 0;
-}
diff --git a/languages/cprogs/glat17.c b/languages/cprogs/glat17.c
deleted file mode 100644
index de5f0cfc..00000000
--- a/languages/cprogs/glat17.c
+++ /dev/null
@@ -1,40 +0,0 @@
-#include
-#include
-unsigned long long int countones(unsigned long long int);
-int main(void)
-{
- unsigned long long int i,cn;
-
- for(i = 1; i<=(ULLONG_MAX - 1); ++i)
- {
- cn = countones(i);
- if( i == cn)
- {
- printf("%d \n",i);
- fflush(stdout);
- }
- }
-
- return 0;
-}
-
-unsigned long long int countones(unsigned long long int i)
-{
- static unsigned long long int count = 0;
- int digit;
-
- while((i/10) >= 1)
- {
- digit = i % 10;
-
- if(digit == 1)
- count++;
- i /= 10;
- }
- if( i == 1)
- count++;
-
- return count;
-}
-
-
diff --git a/languages/cprogs/htoi.c b/languages/cprogs/htoi.c
deleted file mode 100644
index 4af636a3..00000000
--- a/languages/cprogs/htoi.c
+++ /dev/null
@@ -1,70 +0,0 @@
-#include
-#define MAXLINE 100
-
-#define YES 1
-#define NO 0
-
-int getline(char line[],int maxline);
-int htoi(char s[]);
-
-int main(void)
-{
- char line[MAXLINE];
- int value;
-
- getline(line,MAXLINE);
- value=htoi(line);
-
- printf("The value of %s is %d",line,value);
-
- return 0;
-}
-
-int getline(char s[],int lim)
-{
- int c,i;
-
- for(i=0;i='0' && s[i] <='9')
- hexdigit= s[i] - '0';
- else if(s[i] >='a' && s[i] <='f')
- hexdigit= s[i] -'a' + 10;
- else if(s[i] >='A' && s[i] <='F')
- hexdigit= s[i] -'A' + 10;
- else
- inhex = NO;
-
- if(inhex == YES)
- n = 16 * n + hexdigit;
- }
- return n;
-}
-
-
diff --git a/languages/cprogs/leap.c b/languages/cprogs/leap.c
deleted file mode 100644
index b1526433..00000000
--- a/languages/cprogs/leap.c
+++ /dev/null
@@ -1,15 +0,0 @@
-/* Program for the logic of leap year */
-
-#include
-#define YEAR 3000
-
-int main(void)
-{
- if( ((YEAR % 4 == 0) && (YEAR % 100 != 0)) || (YEAR % 400 == 0) )
- printf("The Year is a Leap Year");
- else
- printf("The Year is Not a Leap Year");
-
- return 0;
-}
-
diff --git a/languages/cprogs/likefind.c b/languages/cprogs/likefind.c
deleted file mode 100644
index a03fb451..00000000
--- a/languages/cprogs/likefind.c
+++ /dev/null
@@ -1,66 +0,0 @@
-#include
-#include
-#define MAXLINE 1000
-
-int getline(char *line,int max);
-
-/* find: print lines that match pattern from the 1st arg
- ----------------------------
- find -nx pattern
- ----------------------------
-*/
-
-int main(int argc,char *argv[])
-{
- char line[MAXLINE];
- long lineno = 0;
- int c,except =0,number =0,found =0;
-
- while(--argc > 0 && (*++argv)[0] == '-')
- while(c = *++argv[0])
- switch(c)
- {
- case 'x':
- except =1;
- break;
- case 'n':
- number =1;
- break;
- default:
- printf("find: illegal option %c\n",c);
- argc =0;
- found = -1;
- break;
- }
- if(argc != 1)
- printf("Usage: find -x -n pattern \n");
- else
- while(getline(line,MAXLINE) >0)
- {
- lineno++;
- if((strstr(line,*argv)!=NULL) != except)
- {
- if(number)
- printf("%ld:",lineno);
- printf("%s",line);
- found++;
- }
- }
- return found;
-}
-
-int getline(char *s,int lim)
-{
- int c;
- char *t=s;
-
- while(--lim > 0 && (c=getchar())!=EOF && c!='\n')
- *s++ =c;
-
- if(c=='\n')
- *s++=c;
- *s ='\0';
-
- return s -t;
-}
-
diff --git a/languages/cprogs/likegrep.c b/languages/cprogs/likegrep.c
deleted file mode 100644
index 3aae9099..00000000
--- a/languages/cprogs/likegrep.c
+++ /dev/null
@@ -1,42 +0,0 @@
-/* Ex5.6 */
-
-#include
-#include
-#define MAXLINE 1000
-
-int getline(char *line,int max);
-
-/* find: prints lines that match the pattern from the 1st argument */
-
-int main(int argc,char *argv[])
-{
- char line[MAXLINE];
- int found = 0;
-
- if(argc!=2)
- printf("Usage:find pattern\n");
- else
- while(getline(line,MAXLINE)>0)
- if(strstr(line,argv[1]) != NULL)
- {
- printf("%s",line);
- found++;
- }
- return found;
-}
-
-int getline(char *s,int lim)
-{
- int c;
- char *t=s;
-
- while(--lim > 0 && (c=getchar())!=EOF && c!='\n')
- *s++=c;
-
- if(c=='\n')
- *s++=c;
- *s='\0';
-
- return s-t;
-}
-
diff --git a/languages/cprogs/long_extnal.c b/languages/cprogs/long_extnal.c
deleted file mode 100644
index 419e1fee..00000000
--- a/languages/cprogs/long_extnal.c
+++ /dev/null
@@ -1,50 +0,0 @@
-/* Longest Line Program using External Variables*/
-
-#include
-#define MAXLEN 1000
-
-char line[MAXLEN],longest[MAXLEN];
-
-int getline(void);
-void copy(void);
-
-int main(void)
-{
- int len,max;
- max = 0;
- while((len=getline())>0)
- {
- if( len > max)
- {
- max = len;
- copy();
- }
- }
- if( max > 0)
- printf("%s",longest);
-
- return 0;
-}
-int getline()
-{
- int c,i;
-
- for(i=0;i
-#include
-
-int main(int argc, char *argv[])
-{
- mkdir("foobar",'644');
-}
diff --git a/languages/cprogs/mined1.c b/languages/cprogs/mined1.c
deleted file mode 100644
index 7c1f88fb..00000000
--- a/languages/cprogs/mined1.c
+++ /dev/null
@@ -1,1987 +0,0 @@
-/*
- * Part one of the mined editor.
- */
-
-/*
- * Author: Michiel Huisjes.
- *
- * 1. General remarks.
- *
- * Mined is a screen editor designed for the MINIX operating system.
- * It is meant to be used on files not larger than 50K and to be fast.
- * When mined starts up, it reads the file into its memory to minimize
- * disk access. The only time that disk access is needed is when certain
- * save, write or copy commands are given.
- *
- * Mined has the style of Emacs or Jove, that means that there are no modes.
- * Each character has its own entry in an 256 pointer to function array,
- * which is called when that character is typed. Only ASCII characters are
- * connected with a function that inserts that character at the current
- * location in the file. Two execptions are and which are
- * inserted as well. Note that the mapping between commands and functions
- * called is implicit in the table. Changing the mapping just implies
- * changing the pointers in this table.
- *
- * The display consists of SCREENMAX + 1 lines and XMAX + 1 characters. When
- * a line is larger (or gets larger during editing) than XBREAK characters,
- * the line is either shifted SHIFT_SIZE characters to the left (which means
- * that the first SHIFT_SIZE characters are not printed) or the end of the
- * line is marked with the SHIFT_MARK character and the rest of the line is
- * not printed. A line can never exceed MAX_CHARS characters. Mined will
- * always try to keep the cursor on the same line and same (relative)
- * x-coordinate if nothing changed. So if you scroll one line up, the cursor
- * stays on the same line, or when you move one line down, the cursor will
- * move to the same place on the line as it was on the previous.
- * Every character on the line is available for editing including the
- * linefeed at the the of the line. When the linefeed is deleted, the current
- * line and the next line are joined. The last character of the file (which
- * is always a linefeed) can never be deleted.
- * The bottomline (as indicated by YMAX + 1) is used as a status line during
- * editing. This line is usually blank or contains information mined needs
- * during editing. This information (or rather questions) is displayed in
- * reverse video.
- *
- * The terminal modes are changed completely. All signals like start/stop,
- * interrupt etc. are unset. The only signal that remains is the quit signal.
- * The quit signal (^\) is the general abort signal for mined. Typing a ^\
- * during searching or when mined is asking for filenames, etc. will abort
- * the function and mined will return to the main loop. Sending a quit
- * signal during the main loop will abort the session (after confirmation)
- * and the file is not (!) saved.
- * The session will also be aborted when an unrecoverable error occurs. E.g
- * when there is no more memory available. If the file has been modified,
- * mined will ask if the file has to be saved or not.
- * If there is no more space left on the disk, mined will just give an error
- * message and continue.
- *
- * The number of system calls are minized. This is done to keep the editor
- * as fast as possible. I/O is done in SCREEN_SIZE reads/writes. Accumulated
- * output is also flushed at the end of each character typed.
- *
- * 2. Regular expressions
- *
- * Mined has a build in regular expression matcher, which is used for
- * searching and replace routines. A regular expression consists of a
- * sequence of:
- *
- * 1. A normal character matching that character.
- * 2. A . matching any character.
- * 3. A ^ matching the begin of a line.
- * 4. A $ (as last character of the pattern) mathing the end of a line.
- * 5. A \ matching .
- * 6. A number of characters enclosed in [] pairs matching any of these
- * characters. A list of characters can be indicated by a '-'. So
- * [a-z] matches any letter of the alphabet. If the first character
- * after the '[' is a '^' then the set is negated (matching none of
- * the characters).
- * A ']', '^' or '-' can be escaped by putting a '\' in front of it.
- * Of course this means that a \ must be represented by \\.
- * 7. If one of the expressions as described in 1-6 is followed by a
- * '*' than that expressions matches a sequence of 0 or more of
- * that expression.
- *
- * Parsing of regular expression is done in two phases. In the first phase
- * the expression is compiled into a more comprehensible form. In the second
- * phase the actual matching is done. For more details see 3.6.
- *
- *
- * 3. Implementation of mined.
- *
- * 3.1 Data structures.
- *
- * The main data structures are as follows. The whole file is kept in a
- * double linked list of lines. The LINE structure looks like this:
- *
- * typedef struct Line {
- * struct Line *next;
- * struct Line *prev;
- * char *text;
- * unsigned char shift_count;
- * } LINE;
- *
- * Each line entry contains a pointer to the next line, a pointer to the
- * previous line and a pointer to the text of that line. A special field
- * shift_count contains the number of shifts (in units of SHIFT_SIZE)
- * that is performed on that line. The total size of the structure is 7
- * bytes so a file consisting of 1000 empty lines will waste a lot of
- * memory. A LINE structure is allocated for each line in the file. After
- * that the number of characters of the line is counted and sufficient
- * space is allocated to store them (including a linefeed and a '\0').
- * The resulting address is assigned to the text field in the structure.
- *
- * A special structure is allocated and its address is assigned to the
- * variable header as well as the variable tail. The text field of this
- * structure is set to NIL_PTR. The tail->prev of this structure points
- * to the last LINE of the file and the header->next to the first LINE.
- * Other LINE *variables are top_line and bot_line which point to the
- * first line resp. the last line on the screen.
- * Two other variables are important as well. First the LINE *cur_line,
- * which points to the LINE currently in use and the char *cur_text,
- * which points to the character at which the cursor stands.
- * Whenever an ASCII character is typed, a new line is build with this
- * character inserted. Then the old data space (pointed to by
- * cur_line->text) is freed, data space for the new line is allocated and
- * assigned to cur_line->text.
- *
- * Two global variables called x and y represent the x and y coordinates
- * from the cursor. The global variable nlines contains the number of
- * lines in the file. Last_y indicates the maximum y coordinate of the
- * screen (which is usually SCREENMAX).
- *
- * A few strings must be initialized by hand before compiling mined.
- * These string are enter_string, which is printed upon entering mined,
- * rev_video (turn on reverse video), normal_video, rev_scroll (perform a
- * reverse scroll) and pos_string. The last string should hold the
- * absolute position string to be printed for cursor motion. The #define
- * X_PLUS and Y_PLUS should contain the characters to be added to the
- * coordinates x and y (both starting at 0) to finish cursor positioning.
- *
- * 3.2 Starting up.
- *
- * Mined can be called with or without argument and the function
- * load_file () is called with these arguments. load_file () checks
- * if the file exists if it can be read and if it is writable and
- * sets the writable flag accordingly. If the file can be read,
- * load_file () reads a line from the file and stores this line into
- * a structure by calling install_line () and line_insert () which
- * installs the line into the double linked list, until the end of the
- * file is reached.
- * Lines are read by the function get_line (), which buffers the
- * reading in blocks of SCREEN_SIZE. Load_file () also initializes the
- * LINE *variables described above.
- *
- * 3.3 Moving around.
- *
- * Several commands are implemented for moving through the file.
- * Moving up (UP), down (DN) left (LF) and right (RT) are done by the
- * arrow keys. Moving one line below the screen scrolls the screen one
- * line up. Moving one line above the screen scrolls the screen one line
- * down. The functions forward_scroll () and reverse_scroll () take care
- * of that.
- * Several other move functions exist: move to begin of line (BL), end of
- * line (EL) top of screen (HIGH), bottom of screen (LOW), top of file
- * (HO), end of file (EF), scroll one page down (PD), scroll one page up
- * (PU), scroll one line down (SD), scroll one line up (SU) and move to a
- * certain line number (GOTO).
- * Two functions called MN () and MP () each move one word further or
- * backwards. A word is a number of non-blanks seperated by a space, a
- * tab or a linefeed.
- *
- * 3.4 Modifying text.
- *
- * The modifying commands can be separated into two modes. The first
- * being inserting text, and the other deleting text. Two functions are
- * created for these purposes: insert () and delete (). Both are capable
- * of deleting or inserting large amounts of text as well as one
- * character. Insert () must be given the line and location at which
- * the text must be inserted. Is doesn't make any difference whether this
- * text contains linefeeds or not. Delete () must be given a pointer to
- * the start line, a pointer from where deleting should start on that
- * line and the same information about the end position. The last
- * character of the file will never be deleted. Delete () will make the
- * necessary changes to the screen after deleting, but insert () won't.
- * The functions for modifying text are: insert one char (S), insert a
- * file (file_insert (fd)), insert a linefeed and put cursor back to
- * end of line (LIB), delete character under the cursor (DCC), delete
- * before cursor (even linefeed) (DPC), delete next word (DNW), delete
- * previous word (DPC) and delete to end of line (if the cursor is at
- * a linefeed delete line) (DLN).
- *
- * 3.5 Yanking.
- *
- * A few utilities are provided for yanking pieces of text. The function
- * MA () marks the current position in the file. This is done by setting
- * LINE *mark_line and char *mark_text to the current position. Yanking
- * of text can be done in two modes. The first mode just copies the text
- * from the mark to the current position (or visa versa) into a buffer
- * (YA) and the second also deletes the text (DT). Both functions call
- * the function set_up () with the delete flag on or off. Set_up ()
- * checks if the marked position is still a valid one (by using
- * check_mark () and legal ()), and then calls the function yank () with
- * a start and end position in the file. This function copies the text
- * into a scratch_file as indicated by the variable yank_file. This
- * scratch_file is made uniq by the function scratch_file (). At the end
- * of copying yank will (if necessary) delete the text. A global flag
- * called yank_status keeps track of the buffer (or file) status. It is
- * initialized on NOT_VALID and set to EMPTY (by set_up ()) or VALID (by
- * yank ()). Several things can be done with the buffer. It can be
- * inserted somewhere else in the file (PT) or it can be copied into
- * another file (WB), which will be prompted for.
- *
- * 3.6 Search and replace routines.
- *
- * Searching for strings and replacing strings are done by regular
- * expressions. For any expression the function compile () is called
- * with as argument the expression to compile. Compile () returns a
- * pointer to a structure which looks like this:
- *
- * typedef struct regex {
- * union {
- * char *err_mess;
- * int *expression;
- * } result;
- * char status;
- * char *start_ptr;
- * char *end_ptr;
- * } REGEX;
- *
- * If something went wrong during compiling (e.g. an illegal expression
- * was given), the function reg_error () is called, which sets the status
- * field to REG_ERROR and the err_mess field to the error message. If the
- * match must be anchored at the beginning of the line (end of line), the
- * status field is set to BEGIN_LINE (END_LINE). If none of these special
- * cases are true, the field is set to 0 and the function finished () is
- * called. Finished () allocates space to hold the compiled expression
- * and copies this expression into the expression field of the union
- * (bcopy ()). Matching is done by the routines match() and line_check().
- * Match () takes as argument the REGEX *program, a pointer to the
- * startposition on the current line, and a flag indicating FORWARD or
- * REVERSE search. Match () checks out the whole file until a match is
- * found. If match is found it returns a pointer to the line in which the
- * match was found else it returns a NIL_LINE. Line_check () takes the
- * same arguments, but return either MATCH or NO_MATCH.
- * During checking, the start_ptr and end_ptr fields of the REGEX
- * structure are assigned to the start and end of the match.
- * Both functions try to find a match by walking through the line
- * character by character. For each possibility, the function
- * check_string () is called with as arguments the REGEX *program and the
- * string to search in. It starts walking through the expression until
- * the end of the expression or the end of the string is reached.
- * Whenever a * is encountered, this position of the string is marked,
- * the maximum number of matches are performed and the function star ()
- * is called in order to try to find the longest match possible. Star ()
- * takes as arguments the REGEX program, the current position of the
- * string, the marked position and the current position of the expression
- * Star () walks from the current position of the string back to the
- * marked position, and calls string_check () in order to find a match.
- * It returns MATCH or NO_MATCH, just as string_check () does.
- * Searching is now easy. Both search routines (forward (SF) and
- * backwards search (SR)) call search () with an apropiate message and a
- * flag indicating FORWARD or REVERSE search. Search () will get an
- * expression from the user by calling get_expression(). Get_expression()
- * returns a pointer to a REGEX structure or NIL_REG upon errors and
- * prompts for the expression. If no expression if given, the previous is
- * used instead. After that search will call match (), and if a match is
- * found, we can move to that place in the file by the functions find_x()
- * and find_y () which will find display the match on the screen.
- * Replacing can be done in two ways. A global replace (GR) or a line
- * replace (LR). Both functions call change () with a message an a flag
- * indicating global or line replacement. Change () will prompt for the
- * expression and for the replacement. Every & in the replacement pattern
- * means substitute the match instead. An & can be escaped by a \. When
- * a match is found, the function substitute () will perform the
- * substitution.
- *
- * 3.6 Miscellaneous commands.
- *
- * A few commands haven't be discussed yet. These are redraw the screen
- * (RD) fork a shell (SH), print file status (FS), write file to disc
- * (WT), insert a file at current position (IF), leave editor (XT) and
- * visit another file (VI). The last two functions will check if the file
- * has been modified. If it has, they will ask if you want to save the
- * file by calling ask_save ().
- * The function ESC () will repeat a command n times. It will prompt for
- * the number. Aborting the loop can be done by sending the ^\ signal.
- *
- * 3.7 Utility functions.
- *
- * Several functions exists for internal use. First allocation routines:
- * alloc (bytes) and newline () will return a pointer to free data space
- * if the given size. If there is no more memory available, the function
- * panic () is called.
- * Signal handling: The only signal that can be send to mined is the
- * SIGQUIT signal. This signal, functions as a general abort command.
- * Mined will abort if the signal is given during the main loop. The
- * function abort_mined () takes care of that.
- * Panic () is a function with as argument a error message. It will print
- * the message and the error number set by the kernel (errno) and will
- * ask if the file must be saved or not. It resets the terminal
- * (raw_mode ()) and exits.
- * String handling routines like copy_string(to, from), length_of(string)
- * and build_string (buffer, format, arg1, arg2, ...). The latter takes
- * a description of the string out out the format field and puts the
- * result in the buffer. (It works like printf (3), but then into a
- * string). The functions status_line (string1, string2), error (string1,
- * string2), clear_status () and bottom_line () all print information on
- * the status line.
- * Get_string (message, buffer) reads a string and getchar () reads one
- * character from the terminal.
- * Num_out ((long) number) prints the number into a 11 digit field
- * without leading zero's. It returns a pointer to the resulting string.
- * File_status () prints all file information on the status line.
- * Set_cursor (x, y) prints the string to put the cursor at coordinates
- * x and y.
- * Output is done by four functions: writeline(fd,string), clear_buffer()
- * write_char (fd, c) and flush_buffer (fd). Three defines are provided
- * to write on filedescriptor STD_OUT (terminal) which is used normally:
- * string_print (string), putchar (c) and flush (). All these functions
- * use the global I/O buffer screen and the global index for this array
- * called out_count. In this way I/O can be buffered, so that reads or
- * writes can be done in blocks of SCREEN_SIZE size.
- * The following functions all handle internal line maintenance. The
- * function proceed (start_line, count) returns the count'th line after
- * start_line. If count is negative, the count'th line before the
- * start_line is returned. If header or tail is encountered then that
- * will be returned. Display (x, y, start_line, count) displays count
- * lines starting at coordinates [x, y] and beginning at start_line. If
- * the header or tail is encountered, empty lines are displayed instead.
- * The function reset (head_line, ny) reset top_line, last_y, bot_line,
- * cur_line and y-coordinate. This is not a neat way to do the
- * maintenance, but it sure saves a lot of code. It is usually used in
- * combination with display ().
- * Put_line(line, offset, clear_line), prints a line (skipping characters
- * according to the line->shift_size field) until XBREAK - offset
- * characters are printed or a '\n' is encountered. If clear_line is
- * TRUE, spaces are printed until XBREAK - offset characters.
- * Line_print (line) is a #define from put_line (line, 0, TRUE).
- * Moving is done by the functions move_to (x, y), move_addres (address)
- * and move (x, adress, y). This function is the most important one in
- * mined. New_y must be between 0 and last_y, new_x can be about
- * anything, address must be a pointer to an character on the current
- * line (or y). Move_to () first adjust the y coordinate together with
- * cur_line. If an address is given, it finds the corresponding
- * x-coordinate. If an new x-coordinate was given, it will try to locate
- * the corresponding character. After that it sets the shift_count field
- * of cur_line to an apropiate number according to new_x. The only thing
- * left to do now is to assign the new values to cur_line, cur_text, x
- * and y.
- *
- * 4. Summary of commands.
- *
- * CURSOR MOTION
- * up-arrow Move cursor 1 line up. At top of screen, reverse scroll
- * down-arrow Move cursor 1 line down. At bottom, scroll forward.
- * left-arrow Move cursor 1 character left or to end of previous line
- * right-arrow Move cursor 1 character right or to start of next line
- * CTRL-A Move cursor to start of current line
- * CTRL-Z Move cursor to end of current line
- * CTRL-^ Move cursor to top of screen
- * CTRL-_ Move cursor to bottom of screen
- * CTRL-F Forward to start of next word (even to next line)
- * CTRL-B Backward to first character of previous word
- *
- * SCREEN MOTION
- * Home key Move cursor to first character of file
- * End key Move cursor to last character of file
- * PgUp Scroll backward 1 page. Bottom line becomes top line
- * PgD Scroll backward 1 page. Top line becomes bottom line
- * CTRL-D Scroll screen down one line (reverse scroll)
- * CTRL-U Scroll screen up one line (forward scroll)
- *
- * MODIFYING TEXT
- * ASCII char Self insert character at cursor
- * tab Insert tab at cursor
- * backspace Delete the previous char (left of cursor), even line feed
- * Del Delete the character under the cursor
- * CTRL-N Delete next word
- * CTRL-P Delete previous word
- * CTRL-O Insert line feed at cursor and back up 1 character
- * CTRL-T Delete tail of line (cursor to end); if empty, delete line
- * CTRL-@ Set the mark (remember the current location)
- * CTRL-K Delete text from the mark to current position save on file
- * CTRL-C Save the text from the mark to the current position
- * CTRL-Y Insert the contents of the save file at current position
- * CTRL-Q Insert the contents of the save file into a new file
- * CTRL-G Insert a file at the current position
- *
- * MISCELLANEOUS
- * CTRL-E Erase and redraw the screen
- * CTRL-V Visit file (read a new file); complain if old one changed
- * CTRL-W Write the current file back to the disk
- * numeric + Search forward (prompt for regular expression)
- * numeric - Search backward (prompt for regular expression)
- * numeric 5 Print the current status of the file
- * CTRL-R (Global) Replace str1 by str2 (prompts for each string)
- * CTRL-L (Line) Replace string1 by string2
- * CTRL-S Fork off a shell and wait for it to finish
- * CTRL-X EXIT (prompt if file modified)
- * CTRL-] Go to a line. Prompts for linenumber
- * CTRL-\ Abort whatever editor was doing and start again
- * escape key Repeat a command count times; (prompts for count)
- */
-
-/* ======================================================================== *
- * Utilities *
- * ======================================================================== */
-
-#include "mined.h"
-#include
-#include
-#include
-#include
-#include
-#include
-#if __STDC__
-#include
-#else
-#include
-#endif
-
-extern int errno;
-int ymax = YMAX;
-int screenmax = SCREENMAX;
-
-
-/*
- * Print file status.
- */
-void FS()
-{
- fstatus(file_name[0] ? "" : "[buffer]", -1L);
-}
-
-/*
- * Visit (edit) another file. If the file has been modified, ask the user if
- * he wants to save it.
- */
-void VI()
-{
- char new_file[LINE_LEN]; /* Buffer to hold new file name */
-
- if (modified == TRUE && ask_save() == ERRORS)
- return;
-
-/* Get new file name */
- if (get_file("Visit file:", new_file) == ERRORS)
- return;
-
-/* Free old linked list, initialize global variables and load new file */
- initialize();
-#ifdef UNIX
- tputs(CL, 0, _putchar);
-#else
- string_print (enter_string);
-#endif /* UNIX */
- load_file(new_file[0] == '\0' ? NIL_PTR : new_file);
-}
-
-/*
- * Write file in core to disc.
- */
-int WT()
-{
- register LINE *line;
- register long count = 0L; /* Nr of chars written */
- char file[LINE_LEN]; /* Buffer for new file name */
- int fd; /* Filedescriptor of file */
-
- if (modified == FALSE) {
- error ("Write not necessary.", NIL_PTR);
- return FINE;
- }
-
-/* Check if file_name is valid and if file can be written */
- if (file_name[0] == '\0' || writable == FALSE) {
- if (get_file("Enter file name:", file) != FINE)
- return ERRORS;
- copy_string(file_name, file); /* Save file name */
- }
- if ((fd = creat(file_name, 0644)) < 0) { /* Empty file */
- error("Cannot create ", file_name);
- writable = FALSE;
- return ERRORS;
- }
- else
- writable = TRUE;
-
- clear_buffer();
-
- status_line("Writing ", file_name);
- for (line = header->next; line != tail; line = line->next) {
- if (line->shift_count & DUMMY) {
- if (line->next == tail && line->text[0] == '\n')
- continue;
- }
- if (writeline(fd, line->text) == ERRORS) {
- count = -1L;
- break;
- }
- count += (long) length_of(line->text);
- }
-
- if (count > 0L && flush_buffer(fd) == ERRORS)
- count = -1L;
-
- (void) close(fd);
-
- if (count == -1L)
- return ERRORS;
-
- modified = FALSE;
- rpipe = FALSE; /* File name is now assigned */
-
-/* Display how many chars (and lines) were written */
- fstatus("Wrote", count);
- return FINE;
-}
-
-/* Call WT and discard value returned. */
-void XWT()
-{
- (void) WT();
-}
-
-
-
-/*
- * Call an interactive shell.
- */
-void SH()
-{
- register int w;
- int pid, status;
- char *shell;
-
- if ((shell = getenv("SHELL")) == NIL_PTR) shell = "/bin/sh";
-
- switch (pid = fork()) {
- case -1: /* Error */
- error("Cannot fork.", NIL_PTR);
- return;
- case 0: /* This is the child */
- set_cursor(0, ymax);
- putchar('\n');
- flush();
- raw_mode(OFF);
- if (rpipe) { /* Fix stdin */
- close (0);
- if (open("/dev/tty", 0) < 0)
- exit (126);
- }
- execl(shell, shell, (char *) 0);
- exit(127); /* Exit with 127 */
- default : /* This is the parent */
- signal(SIGINT, SIG_IGN);
- signal(SIGQUIT, SIG_IGN);
- do {
- w = wait(&status);
- } while (w != -1 && w != pid);
- }
-
- raw_mode(ON);
- RD();
-
- if ((status >> 8) == 127) /* Child died with 127 */
- error("Cannot exec ", shell);
- else if ((status >> 8) == 126)
- error("Cannot open /dev/tty as fd #0", NIL_PTR);
-}
-
-/*
- * Proceed returns the count'th line after `line'. When count is negative
- * it returns the count'th line before `line'. When the next (previous)
- * line is the tail (header) indicating EOF (tof) it stops.
- */
-LINE *proceed(line, count)
-register LINE *line;
-register int count;
-{
- if (count < 0)
- while (count++ < 0 && line != header)
- line = line->prev;
- else
- while (count-- > 0 && line != tail)
- line = line->next;
- return line;
-}
-
-/*
- * Show concatenation of s1 and s2 on the status line (bottom of screen)
- * If revfl is TRUE, turn on reverse video on both strings. Set stat_visible
- * only if bottom_line is visible.
- */
-int bottom_line(revfl, s1, s2, inbuf, statfl)
-FLAG revfl;
-char *s1, *s2;
-char *inbuf;
-FLAG statfl;
-{
- int ret = FINE;
- char buf[LINE_LEN];
- register char *p = buf;
-
- *p++ = ' ';
- if (s1 != NIL_PTR)
- while (*p = *s1++)
- p++;
- if (s2 != NIL_PTR)
- while (*p = *s2++)
- p++;
- *p++ = ' ';
- *p++ = 0;
-
- if (revfl == ON && stat_visible == TRUE)
- clear_status ();
- set_cursor(0, ymax);
- if (revfl == ON) { /* Print rev. start sequence */
-#ifdef UNIX
- tputs(SO, 0, _putchar);
-#else
- string_print(rev_video);
-#endif /* UNIX */
- stat_visible = TRUE;
- }
- else /* Used as clear_status() */
- stat_visible = FALSE;
-
- string_print(buf);
-
- if (inbuf != NIL_PTR)
- ret = input(inbuf, statfl);
-
- /* Print normal video */
-#ifdef UNIX
- tputs(SE, 0, _putchar);
- tputs(CE, 0, _putchar);
-#else
- string_print(normal_video);
- string_print(blank_line); /* Clear the rest of the line */
-#endif /* UNIX */
- if (inbuf != NIL_PTR)
- set_cursor(0, ymax);
- else
- set_cursor(x, y); /* Set cursor back to old position */
- flush(); /* Perform the actual write */
- if (ret != FINE)
- clear_status();
- return ret;
-}
-
-/*
- * Count_chars() count the number of chars that the line would occupy on the
- * screen. Counting starts at the real x-coordinate of the line.
- */
-int count_chars(line)
-LINE *line;
-{
- register int cnt = get_shift(line->shift_count) * -SHIFT_SIZE;
- register char *textp = line->text;
-
-/* Find begin of line on screen */
- while (cnt < 0) {
- if (is_tab(*textp++))
- cnt = tab(cnt);
- else
- cnt++;
- }
-
-/* Count number of chars left */
- cnt = 0;
- while (*textp != '\n') {
- if (is_tab(*textp++))
- cnt = tab(cnt);
- else
- cnt++;
- }
- return cnt;
-}
-
-/*
- * Move to coordinates nx, ny at screen. The caller must check that scrolling
- * is not needed.
- * If new_x is lower than 0 or higher than XBREAK, move_to() will check if
- * the line can be shifted. If it can it sets(or resets) the shift_count field
- * of the current line accordingly.
- * Move also sets cur_text to the right char.
- * If we're moving to the same x coordinate, try to move the the x-coordinate
- * used on the other previous call.
- */
-void move(new_x, new_address, new_y)
-register int new_x;
-int new_y;
-char *new_address;
-{
- register LINE *line = cur_line; /* For building new cur_line */
- int shift = 0; /* How many shifts to make */
- static int rel_x = 0; /* Remember relative x position */
- int tx = x;
-
-/* Check for illegal values */
- if (new_y < 0 || new_y > last_y)
- return;
-
-/* Adjust y-coordinate and cur_line */
- if (new_y < y)
- while (y != new_y) {
- y--;
- line = line->prev;
- }
- else
- while (y != new_y) {
- y++;
- line = line->next;
- }
-
-/* Set or unset relative x-coordinate */
- if (new_address == NIL_PTR) {
- new_address = find_address(line, (new_x == x) ? rel_x : new_x , &tx);
- if (new_x != x)
- rel_x = tx;
- new_x = tx;
- }
- else
- rel_x = new_x = find_x(line, new_address);
-
-/* Adjust shift_count if new_x lower than 0 or higher than XBREAK */
- if (new_x < 0 || new_x >= XBREAK) {
- if (new_x > XBREAK || (new_x == XBREAK && *new_address != '\n'))
- shift = (new_x - XBREAK) / SHIFT_SIZE + 1;
- else {
- shift = new_x / SHIFT_SIZE;
- if (new_x % SHIFT_SIZE)
- shift--;
- }
-
- if (shift != 0) {
- line->shift_count += shift;
- new_x = find_x(line, new_address);
- set_cursor(0, y);
- line_print(line);
- rel_x = new_x;
- }
- }
-
-/* Assign and position cursor */
- x = new_x;
- cur_text = new_address;
- cur_line = line;
- set_cursor(x, y);
-}
-
-/*
- * Find_x() returns the x coordinate belonging to address.
- * (Tabs are expanded).
- */
-int find_x(line, address)
-LINE *line;
-char *address;
-{
- register char *textp = line->text;
- register int nx = get_shift(line->shift_count) * -SHIFT_SIZE;
-
- while (textp != address && *textp != '\0') {
- if (is_tab(*textp++)) /* Expand tabs */
- nx = tab(nx);
- else
- nx++;
- }
- return nx;
-}
-
-/*
- * Find_address() returns the pointer in the line with offset x_coord.
- * (Tabs are expanded).
- */
-char *find_address(line, x_coord, old_x)
-LINE *line;
-int x_coord;
-int *old_x;
-{
- register char *textp = line->text;
- register int tx = get_shift(line->shift_count) * -SHIFT_SIZE;
-
- while (tx < x_coord && *textp != '\n') {
- if (is_tab(*textp)) {
- if (*old_x - x_coord == 1 && tab(tx) > x_coord)
- break; /* Moving left over tab */
- else
- tx = tab(tx);
- }
- else
- tx++;
- textp++;
- }
-
- *old_x = tx;
- return textp;
-}
-
-/*
- * Length_of() returns the number of characters int the string `string'
- * excluding the '\0'.
- */
-int length_of(string)
-register char *string;
-{
- register int count = 0;
-
- if (string != NIL_PTR) {
- while (*string++ != '\0')
- count++;
- }
- return count;
-}
-
-/*
- * Copy_string() copies the string `from' into the string `to'. `To' must be
- * long enough to hold `from'.
- */
-void copy_string(to, from)
-register char *to;
-register char *from;
-{
- while (*to++ = *from++)
- ;
-}
-
-/*
- * Reset assigns bot_line, top_line and cur_line according to `head_line'
- * which must be the first line of the screen, and an y-coordinate,
- * which will be the current y-coordinate (if it isn't larger than last_y)
- */
-void reset(head_line, screen_y)
-LINE *head_line;
-int screen_y;
-{
- register LINE *line;
-
- top_line = line = head_line;
-
-/* Search for bot_line (might be last line in file) */
- for (last_y = 0; last_y < nlines - 1 && last_y < screenmax
- && line->next != tail; last_y++)
- line = line->next;
-
- bot_line = line;
- y = (screen_y > last_y) ? last_y : screen_y;
-
-/* Set cur_line according to the new y value */
- cur_line = proceed(top_line, y);
-}
-
-/*
- * Set cursor at coordinates x, y.
- */
-void set_cursor(nx, ny)
-int nx, ny;
-{
-#ifdef UNIX
- extern char *tgoto();
-
- tputs(tgoto(CM, nx, ny), 0, _putchar);
-#else
- char text_buffer[10];
-
- build_string(text_buffer, pos_string, ny+1, nx+1);
- string_print(text_buffer);
-#endif /* UNIX */
-}
-
-/*
- * Routine to open terminal when mined is used in a pipeline.
- */
-void open_device()
-{
- if ((input_fd = open("/dev/tty", 0)) < 0)
- panic("Cannot open /dev/tty for read");
-}
-
-/*
- * Getchar() reads one character from the terminal. The character must be
- * masked with 0377 to avoid sign extension.
- */
-int getchar()
-{
-#ifdef UNIX
- return (_getchar() & 0377);
-#else
- char c;
-
- if (read(input_fd, &c, 1) != 1 && quit == FALSE)
- panic("Can't read one char from fd #0");
-
- return c & 0377;
-#endif /* UNIX */
-}
-
-/*
- * Display() shows count lines on the terminal starting at the given
- * coordinates. When the tail of the list is encountered it will fill the
- * rest of the screen with blank_line's.
- * When count is negative, a backwards print from `line' will be done.
- */
-void display(x_coord, y_coord, line, count)
-int x_coord, y_coord;
-register LINE *line;
-register int count;
-{
- set_cursor(x_coord, y_coord);
-
-/* Find new startline if count is negative */
- if (count < 0) {
- line = proceed(line, count);
- count = -count;
- }
-
-/* Print the lines */
- while (line != tail && count-- >= 0) {
- line_print(line);
- line = line->next;
- }
-
-/* Print the blank lines (if any) */
- if (loading == FALSE) {
- while (count-- >= 0) {
-#ifdef UNIX
- tputs(CE, 0, _putchar);
-#else
- string_print(blank_line);
-#endif /* UNIX */
- putchar('\n');
- }
- }
-}
-
-/*
- * Write_char does a buffered output.
- */
-int write_char(fd, c)
-int fd;
-char c;
-{
- screen [out_count++] = c;
- if (out_count == SCREEN_SIZE) /* Flush on SCREEN_SIZE chars */
- return flush_buffer(fd);
- return FINE;
-}
-
-/*
- * Writeline writes the given string on the given filedescriptor.
- */
-int writeline(fd, text)
-register int fd;
-register char *text;
-{
- while(*text)
- if (write_char(fd, *text++) == ERRORS)
- return ERRORS;
- return FINE;
-}
-
-/*
- * Put_line print the given line on the standard output. If offset is not zero
- * printing will start at that x-coordinate. If the FLAG clear_line is TRUE,
- * then (screen) line will be cleared when the end of the line has been
- * reached.
- */
-void put_line(line, offset, clear_line)
-LINE *line; /* Line to print */
-int offset; /* Offset to start */
-FLAG clear_line; /* Clear to eoln if TRUE */
-{
- register char *textp = line->text;
- register int count = get_shift(line->shift_count) * -SHIFT_SIZE;
- int tab_count; /* Used in tab expansion */
-
-/* Skip all chars as indicated by the offset and the shift_count field */
- while (count < offset) {
- if (is_tab(*textp++))
- count = tab(count);
- else
- count++;
- }
-
- while (*textp != '\n' && count < XBREAK) {
- if (is_tab(*textp)) { /* Expand tabs to spaces */
- tab_count = tab(count);
- while (count < XBREAK && count < tab_count) {
- count++;
- putchar(' ');
- }
- textp++;
- }
- else {
- if (*textp >= '\01' && *textp <= '\037') {
-#ifdef UNIX
- tputs(SO, 0, _putchar);
-#else
- string_print (rev_video);
-#endif /* UNIX */
- putchar(*textp++ + '\100');
-#ifdef UNIX
- tputs(SE, 0, _putchar);
-#else
- string_print (normal_video);
-#endif /* UNIX */
- }
- else
- putchar(*textp++);
- count++;
- }
- }
-
-/* If line is longer than XBREAK chars, print the shift_mark */
- if (count == XBREAK && *textp != '\n')
- putchar(textp[1]=='\n' ? *textp : SHIFT_MARK);
-
-/* Clear the rest of the line is clear_line is TRUE */
- if (clear_line == TRUE) {
-#ifdef UNIX
- tputs(CE, 0, _putchar);
-#else
- string_print(blank_line);
-#endif /* UNIX */
- putchar('\n');
- }
-}
-
-/*
- * Flush the I/O buffer on filedescriptor fd.
- */
-int flush_buffer(fd)
-int fd;
-{
- if (out_count <= 0) /* There is nothing to flush */
- return FINE;
-#ifdef UNIX
- if (fd == STD_OUT) {
- printf("%.*s", out_count, screen);
- _flush();
- }
- else
-#endif /* UNIX */
- if (write(fd, screen, out_count) != out_count) {
- bad_write(fd);
- return ERRORS;
- }
- clear_buffer(); /* Empty buffer */
- return FINE;
-}
-
-/*
- * Bad_write() is called when a write failed. Notify the user.
- */
-void bad_write(fd)
-int fd;
-{
- if (fd == STD_OUT) /* Cannot write to terminal? */
- exit(1);
-
- clear_buffer();
- build_string(text_buffer, "Command aborted: %s (File incomplete)",
- (errno == ENOSPC || errno == -ENOSPC) ?
- "No space on device" : "Write error");
- error(text_buffer, NIL_PTR);
-}
-
-/*
- * Catch the SIGQUIT signal (^\) send to mined. It turns on the quitflag.
- */
-void catch(sig)
-int sig;
-{
-/* Reset the signal */
- signal(SIGQUIT, catch);
- quit = TRUE;
-}
-
-/*
- * Abort_mined() will leave mined. Confirmation is asked first.
- */
-void abort_mined()
-{
- quit = FALSE;
-
-/* Ask for confirmation */
- status_line("Really abort? ", NIL_PTR);
- if (getchar() != 'y') {
- clear_status();
- return;
- }
-
-/* Reset terminal */
- raw_mode(OFF);
- set_cursor(0, ymax);
- putchar('\n');
- flush();
-#ifdef UNIX
- abort();
-#else
- exit(1);
-#endif /* UNIX */
-}
-
-#define UNDEF _POSIX_VDISABLE
-
-/*
- * Set and reset tty into CBREAK or old mode according to argument `state'. It
- * also sets all signal characters (except for ^\) to UNDEF. ^\ is caught.
- */
-void raw_mode(state)
-FLAG state;
-{
- static struct termios old_tty;
- static struct termios new_tty;
-
- if (state == OFF) {
- tcsetattr(input_fd, TCSANOW, &old_tty);
- return;
- }
-
-/* Save old tty settings */
- tcgetattr(input_fd, &old_tty);
-
-/* Set tty to CBREAK mode */
- tcgetattr(input_fd, &new_tty);
- new_tty.c_lflag &= ~(ICANON|ECHO|ECHONL);
- new_tty.c_iflag &= ~(IXON|IXOFF);
-
-/* Unset signal chars, leave only SIGQUIT set to ^\ */
- new_tty.c_cc[VINTR] = new_tty.c_cc[VSUSP] = UNDEF;
- new_tty.c_cc[VQUIT] = '\\' & 037;
- signal(SIGQUIT, catch); /* Which is caught */
-
- tcsetattr(input_fd, TCSANOW, &new_tty);
-}
-
-/*
- * Panic() is called with an error number and a message. It is called when
- * something unrecoverable has happened.
- * It writes the message to the terminal, resets the tty and exits.
- * Ask the user if he wants to save his file.
- */
-void panic(message)
-register char *message;
-{
- extern char yank_file[];
-
-#ifdef UNIX
- tputs(CL, 0, _putchar);
- build_string(text_buffer, "%s\nError code %d\n", message, errno);
-#else
- build_string(text_buffer, "%s%s\nError code %d\n", enter_string, message, errno);
-#endif /* UNIX */
- (void) write(STD_OUT, text_buffer, length_of(text_buffer));
-
- if (loading == FALSE)
- XT(); /* Check if file can be saved */
- else
- (void) unlink(yank_file);
- raw_mode(OFF);
-
-#ifdef UNIX
- abort();
-#else
- exit(1);
-#endif /* UNIX */
-}
-
-char *alloc(bytes)
-int bytes;
-{
- char *p;
-
- p = malloc((unsigned) bytes);
- if (p == NIL_PTR) {
- if (loading == TRUE)
- panic("File too big.");
- panic("Out of memory.");
- }
- return(p);
-}
-
-void free_space(p)
-char *p;
-{
- free(p);
-}
-
-/* ======================================================================== *
- * Main loops *
- * ======================================================================== */
-
-/* The mapping between input codes and functions. */
-
-void (*key_map[256])() = { /* map ASCII characters to functions */
- /* 000-017 */ MA, BL, MP, YA, SD, RD, MN, IF, DPC, S, S, DT, LR, S, DNW,LIB,
- /* 020-037 */ DPW, WB, GR, SH, DLN, SU, VI, XWT, XT, PT, EL, ESC, I, GOTO,
- HIGH, LOW,
- /* 040-057 */ S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S,
- /* 060-077 */ S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S,
- /* 100-117 */ S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S,
- /* 120-137 */ S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S,
- /* 140-157 */ S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S,
- /* 160-177 */ S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, DCC,
- /* 200-217 */ S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S,
- /* 220-237 */ S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S,
- /* 240-257 */ S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S,
- /* 260-277 */ S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S,
- /* 300-317 */ S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S,
- /* 320-337 */ S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S,
- /* 340-357 */ S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S,
- /* 360-377 */ S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S,
-};
-
-int nlines; /* Number of lines in file */
-LINE *header; /* Head of line list */
-LINE *tail; /* Last line in line list */
-LINE *cur_line; /* Current line in use */
-LINE *top_line; /* First line of screen */
-LINE *bot_line; /* Last line of screen */
-char *cur_text; /* Current char on current line in use */
-int last_y; /* Last y of screen. Usually SCREENMAX */
-char screen[SCREEN_SIZE]; /* Output buffer for "writes" and "reads" */
-
-int x, y; /* x, y coordinates on screen */
-FLAG modified = FALSE; /* Set when file is modified */
-FLAG stat_visible; /* Set if status_line is visible */
-FLAG writable; /* Set if file cannot be written */
-FLAG loading; /* Set if we are loading a file. */
-FLAG quit = FALSE; /* Set when quit character is typed */
-FLAG rpipe = FALSE; /* Set if file should be read from stdin */
-int input_fd = 0; /* Fd for command input */
-int out_count; /* Index in output buffer */
-char file_name[LINE_LEN]; /* Name of file in use */
-char text_buffer[MAX_CHARS]; /* Buffer for modifying text */
-
-/* Escape sequences. */
-#ifdef UNIX
-char *CE, *VS, *SO, *SE, *CL, *AL, *CM;
-#else
-char *enter_string = "\033[H\033[J"; /* String printed on entering mined */
-char *pos_string = "\033[%d;%dH"; /* Absolute cursor position */
-char *rev_scroll = "\033M"; /* String for reverse scrolling */
-char *rev_video = "\033[7m"; /* String for starting reverse video */
-char *normal_video = "\033[m"; /* String for leaving reverse video */
-char *blank_line = "\033[K"; /* Clear line to end */
-#endif /* UNIX */
-
-/*
- * Yank variables.
- */
-FLAG yank_status = NOT_VALID; /* Status of yank_file */
-char yank_file[] = "/tmp/mined.XXXXXX";
-long chars_saved; /* Nr of chars in buffer */
-
-/*
- * Initialize is called when a another file is edited. It free's the allocated
- * space and sets modified back to FALSE and fixes the header/tail pointer.
- */
-void initialize()
-{
- register LINE *line, *next_line;
-
-/* Delete the whole list */
- for (line = header->next; line != tail; line = next_line) {
- next_line = line->next;
- free_space(line->text);
- free_space((char*)line);
- }
-
-/* header and tail should point to itself */
- line->next = line->prev = line;
- x = y = 0;
- rpipe = modified = FALSE;
-}
-
-/*
- * Basename() finds the absolute name of the file out of a given path_name.
- */
-char *basename(path)
-char *path;
-{
- register char *ptr = path;
- register char *last = NIL_PTR;
-
- while (*ptr != '\0') {
- if (*ptr == '/')
- last = ptr;
- ptr++;
- }
- if (last == NIL_PTR)
- return path;
- if (*(last + 1) == '\0') { /* E.g. /usr/tmp/pipo/ */
- *last = '\0';
- return basename(path);/* Try again */
- }
- return last + 1;
-}
-
-/*
- * Load_file loads the file `file' into core. If file is a NIL_PTR or the file
- * couldn't be opened, just some initializations are done, and a line consisting
- * of a `\n' is installed.
- */
-void load_file(file)
-char *file;
-{
- register LINE *line = header;
- register int len;
- long nr_of_chars = 0L;
- int fd = -1; /* Filedescriptor for file */
-
- nlines = 0; /* Zero lines to start with */
-
-/* Open file */
- writable = TRUE; /* Benefit of the doubt */
- if (file == NIL_PTR) {
- if (rpipe == FALSE)
- status_line("No file.", NIL_PTR);
- else {
- fd = 0;
- file = "standard input";
- }
- file_name[0] = '\0';
- }
- else {
- copy_string(file_name, file); /* Save file name */
- if (access(file, 0) < 0) /* Cannot access file. */
- status_line("New file ", file);
- else if ((fd = open(file, 0)) < 0)
- status_line("Cannot open ", file);
- else if (access(file, 2) != 0) /* Set write flag */
- writable = FALSE;
- }
-
-/* Read file */
- loading = TRUE; /* Loading file, so set flag */
-
- if (fd >= 0) {
- status_line("Reading ", file);
- while ((len = get_line(fd, text_buffer)) != ERRORS) {
- line = line_insert(line, text_buffer, len);
- nr_of_chars += (long) len;
- }
- if (nlines == 0) /* The file was empty! */
- line = line_insert(line, "\n", 1);
- clear_buffer(); /* Clear output buffer */
- cur_line = header->next;
- fstatus("Read", nr_of_chars);
- (void) close(fd); /* Close file */
- }
- else /* Just install a "\n" */
- (void) line_insert(line, "\n", 1);
-
- reset(header->next, 0); /* Initialize pointers */
-
-/* Print screen */
- display (0, 0, header->next, last_y);
- move_to (0, 0);
- flush(); /* Flush buffer */
- loading = FALSE; /* Stop loading, reset flag */
-}
-
-
-/*
- * Get_line reads one line from filedescriptor fd. If EOF is reached on fd,
- * get_line() returns ERRORS, else it returns the length of the string.
- */
-int get_line(fd, buffer)
-int fd;
-register char *buffer;
-{
- static char *last = NIL_PTR;
- static char *current = NIL_PTR;
- static int read_chars;
- register char *cur_pos = current;
- char *begin = buffer;
-
- do {
- if (cur_pos == last) {
- if ((read_chars = read(fd, screen, SCREEN_SIZE)) <= 0)
- break;
- last = &screen[read_chars];
- cur_pos = screen;
- }
- if (*cur_pos == '\0')
- *cur_pos = ' ';
- } while ((*buffer++ = *cur_pos++) != '\n');
-
- current = cur_pos;
- if (read_chars <= 0) {
- if (buffer == begin)
- return ERRORS;
- if (*(buffer - 1) != '\n')
- if (loading == TRUE) /* Add '\n' to last line of file */
- *buffer++ = '\n';
- else {
- *buffer = '\0';
- return NO_LINE;
- }
- }
-
- *buffer = '\0';
- return buffer - begin;
-}
-
-/*
- * Install_line installs the buffer into a LINE structure It returns a pointer
- * to the allocated structure.
- */
-LINE *install_line(buffer, length)
-char *buffer;
-int length;
-{
- register LINE *new_line = (LINE *) alloc(sizeof(LINE));
-
- new_line->text = alloc(length + 1);
- new_line->shift_count = 0;
- copy_string(new_line->text, buffer);
-
- return new_line;
-}
-
-void main(argc, argv)
-int argc;
-char *argv[];
-{
-/* mined is the Minix editor. */
-
- register int index; /* Index in key table */
- struct winsize winsize;
-
-#ifdef UNIX
- get_term();
- tputs(VS, 0, _putchar);
- tputs(CL, 0, _putchar);
-#else
- string_print(enter_string); /* Hello world */
-#endif /* UNIX */
- if (ioctl(STD_OUT, TIOCGWINSZ, &winsize) == 0 && winsize.ws_row != 0) {
- ymax = winsize.ws_row - 1;
- screenmax = ymax - 1;
- }
-
- if (!isatty(0)) { /* Reading from pipe */
- if (argc != 1) {
- write(2, "Cannot find terminal.\n", 22);
- exit (1);
- }
- rpipe = TRUE;
- modified = TRUE; /* Set modified so he can write */
- open_device();
- }
-
- raw_mode(ON); /* Set tty to appropriate mode */
-
- header = tail = (LINE *) alloc(sizeof(LINE)); /* Make header of list*/
- header->text = NIL_PTR;
- header->next = tail->prev = header;
-
-/* Load the file (if any) */
- if (argc < 2)
- load_file(NIL_PTR);
- else {
- (void) get_file(NIL_PTR, argv[1]); /* Truncate filename */
- load_file(argv[1]);
- }
-
- /* Main loop of the editor. */
- for (;;) {
- index = getchar();
- if (stat_visible == TRUE)
- clear_status();
- if (quit == TRUE)
- abort_mined();
- else { /* Call the function for this key */
- (*key_map[index])(index);
- flush(); /* Flush output (if any) */
- if (quit == TRUE)
- quit = FALSE;
- }
- }
- /* NOTREACHED */
-}
-
-/* ======================================================================== *
- * Miscellaneous *
- * ======================================================================== */
-
-/*
- * Redraw the screen
- */
-void RD()
-{
-/* Clear screen */
-#ifdef UNIX
- tputs(VS, 0, _putchar);
- tputs(CL, 0, _putchar);
-#else
- string_print(enter_string);
-#endif /* UNIX */
-
-/* Print first page */
- display(0, 0, top_line, last_y);
-
-/* Clear last line */
- set_cursor(0, ymax);
-#ifdef UNIX
- tputs(CE, 0, _putchar);
-#else
- string_print(blank_line);
-#endif /* UNIX */
- move_to(x, y);
-}
-
-/*
- * Ignore this keystroke.
- */
-void I()
-{
-}
-
-/*
- * Leave editor. If the file has changed, ask if the user wants to save it.
- */
-void XT()
-{
- if (modified == TRUE && ask_save() == ERRORS)
- return;
-
- raw_mode(OFF);
- set_cursor(0, ymax);
- putchar('\n');
- flush();
- (void) unlink(yank_file); /* Might not be necessary */
- exit(0);
-}
-
-void (*escfunc(c))()
-int c;
-{
-#if (CHIP == M68000)
-#ifndef COMPAT
- int ch;
-#endif
-#endif
- if (c == '[') {
- /* Start of ASCII escape sequence. */
- c = getchar();
-#if (CHIP == M68000)
-#ifndef COMPAT
- if ((c >= '0') && (c <= '9')) ch = getchar();
- /* ch is either a tilde or a second digit */
-#endif
-#endif
- switch (c) {
- case 'H': return(HO);
- case 'A': return(UP);
- case 'B': return(DN);
- case 'C': return(RT);
- case 'D': return(LF);
-#if (CHIP == M68000)
-#ifndef COMPAT
- /* F1 = ESC [ 1 ~ */
- /* F2 = ESC [ 2 ~ */
- /* F3 = ESC [ 3 ~ */
- /* F4 = ESC [ 4 ~ */
- /* F5 = ESC [ 5 ~ */
- /* F6 = ESC [ 6 ~ */
- /* F7 = ESC [ 17 ~ */
- /* F8 = ESC [ 18 ~ */
- case '1':
- switch (ch) {
- case '~': return(SF);
- case '7': (void) getchar(); return(MA);
- case '8': (void) getchar(); return(CTL);
- }
- case '2': return(SR);
- case '3': return(PD);
- case '4': return(PU);
- case '5': return(FS);
- case '6': return(EF);
-#endif
-#endif
-#if (CHIP == INTEL)
- case 'G': return(FS);
- case 'S': return(SR);
- case 'T': return(SF);
- case 'U': return(PD);
- case 'V': return(PU);
- case 'Y': return(EF);
-#endif
- }
- return(I);
- }
-#if (CHIP == M68000)
-#ifdef COMPAT
- if (c == 'O') {
- /* Start of ASCII function key escape sequence. */
- switch (getchar()) {
- case 'P': return(SF);
- case 'Q': return(SR);
- case 'R': return(PD);
- case 'S': return(PU);
- case 'T': return(FS);
- case 'U': return(EF);
- case 'V': return(MA);
- case 'W': return(CTL);
- }
- }
-#endif
-#endif
- return(I);
-}
-
-/*
- * ESC() wants a count and a command after that. It repeats the
- * command count times. If a ^\ is given during repeating, stop looping and
- * return to main loop.
- */
-void ESC()
-{
- register int count = 0;
- register void (*func)();
- int index;
-
- index = getchar();
- while (index >= '0' && index <= '9' && quit == FALSE) {
- count *= 10;
- count += index - '0';
- index = getchar();
- }
- if (count == 0) {
- count = 1;
- func = escfunc(index);
- } else {
- func = key_map[index];
- if (func == ESC)
- func = escfunc(getchar());
- }
-
- if (func == I) { /* Function assigned? */
- clear_status();
- return;
- }
-
- while (count-- > 0 && quit == FALSE) {
- if (stat_visible == TRUE)
- clear_status();
- (*func)(index);
- flush();
- }
-
- if (quit == TRUE) /* Abort has been given */
- error("Aborted", NIL_PTR);
-}
-
-/*
- * Ask the user if he wants to save his file or not.
- */
-int ask_save()
-{
- register int c;
-
- status_line(file_name[0] ? basename(file_name) : "[buffer]" ,
- " has been modified. Save? (y/n)");
-
- while((c = getchar()) != 'y' && c != 'n' && quit == FALSE) {
- ring_bell();
- flush();
- }
-
- clear_status();
-
- if (c == 'y')
- return WT();
-
- if (c == 'n')
- return FINE;
-
- quit = FALSE; /* Abort character has been given */
- return ERRORS;
-}
-
-/*
- * Line_number() finds the line number we're on.
- */
-int line_number()
-{
- register LINE *line = header->next;
- register int count = 1;
-
- while (line != cur_line) {
- count++;
- line = line->next;
- }
-
- return count;
-}
-
-/*
- * Display a line telling how many chars and lines the file contains. Also tell
- * whether the file is readonly and/or modified.
- */
-void file_status(message, count, file, lines, writefl, changed)
-char *message;
-register long count; /* Contains number of characters in file */
-char *file;
-int lines;
-FLAG writefl, changed;
-{
- register LINE *line;
- char msg[LINE_LEN + 40];/* Buffer to hold line */
- char yank_msg[LINE_LEN];/* Buffer for msg of yank_file */
-
- if (count < 0) /* Not valid. Count chars in file */
- for (line = header->next; line != tail; line = line->next)
- count += length_of(line->text);
-
- if (yank_status != NOT_VALID) /* Append buffer info */
- build_string(yank_msg, " Buffer: %D char%s.", chars_saved,
- (chars_saved == 1L) ? "" : "s");
- else
- yank_msg[0] = '\0';
-
- build_string(msg, "%s %s%s%s %d line%s %D char%s.%s Line %d", message,
- (rpipe == TRUE && *message != '[') ? "standard input" : basename(file),
- (changed == TRUE) ? "*" : "",
- (writefl == FALSE) ? " (Readonly)" : "",
- lines, (lines == 1) ? "" : "s",
- count, (count == 1L) ? "" : "s",
- yank_msg, line_number());
-
- if (length_of(msg) + 1 > LINE_LEN - 4) {
- msg[LINE_LEN - 4] = SHIFT_MARK; /* Overflow on status line */
- msg[LINE_LEN - 3] = '\0';
- }
- status_line(msg, NIL_PTR); /* Print the information */
-}
-
-/*
- * Build_string() prints the arguments as described in fmt, into the buffer.
- * %s indicates an argument string, %d indicated an argument number.
- */
-#if __STDC__
-void build_string(char *buf, char *fmt, ...)
-{
-#else
-void build_string(buf, fmt, va_alist)
-char *buf, *fmt;
-va_dcl
-{
-#endif
- va_list argptr;
- char *scanp;
-
-#if __STDC__
- va_start(argptr, fmt);
-#else
- va_start(argptr);
-#endif
-
- while (*fmt) {
- if (*fmt == '%') {
- fmt++;
- switch (*fmt++) {
- case 's' :
- scanp = va_arg(argptr, char *);
- break;
- case 'd' :
- scanp = num_out((long) va_arg(argptr, int));
- break;
- case 'D' :
- scanp = num_out((long) va_arg(argptr, long));
- break;
- default :
- scanp = "";
- }
- while (*buf++ = *scanp++)
- ;
- buf--;
- }
- else
- *buf++ = *fmt++;
- }
- va_end(argptr);
- *buf = '\0';
-}
-
-/*
- * Output an (unsigned) long in a 10 digit field without leading zeros.
- * It returns a pointer to the first digit in the buffer.
- */
-char *num_out(number)
-long number;
-{
- static char num_buf[11]; /* Buffer to build number */
- register long digit; /* Next digit of number */
- register long pow = 1000000000L; /* Highest ten power of long */
- FLAG digit_seen = FALSE;
- int i;
-
- for (i = 0; i < 10; i++) {
- digit = number / pow; /* Get next digit */
- if (digit == 0L && digit_seen == FALSE && i != 9)
- num_buf[i] = ' ';
- else {
- num_buf[i] = '0' + (char) digit;
- number -= digit * pow; /* Erase digit */
- digit_seen = TRUE;
- }
- pow /= 10L; /* Get next digit */
- }
- for (i = 0; num_buf[i] == ' '; i++) /* Skip leading spaces */
- ;
- return (&num_buf[i]);
-}
-
-/*
- * Get_number() read a number from the terminal. The last character typed in is
- * returned. ERRORS is returned on a bad number. The resulting number is put
- * into the integer the arguments points to.
- */
-int get_number(message, result)
-char *message;
-int *result;
-{
- register int index;
- register int count = 0;
-
- status_line(message, NIL_PTR);
-
- index = getchar();
- if (quit == FALSE && (index < '0' || index > '9')) {
- error("Bad count", NIL_PTR);
- return ERRORS;
- }
-
-/* Convert input to a decimal number */
- while (index >= '0' && index <= '9' && quit == FALSE) {
- count *= 10;
- count += index - '0';
- index = getchar();
- }
-
- if (quit == TRUE) {
- clear_status();
- return ERRORS;
- }
-
- *result = count;
- return index;
-}
-
-/*
- * Input() reads a string from the terminal. When the KILL character is typed,
- * it returns ERRORS.
- */
-int input(inbuf, clearfl)
-char *inbuf;
-FLAG clearfl;
-{
- register char *ptr;
- register char c; /* Character read */
-
- ptr = inbuf;
-
- *ptr = '\0';
- while (quit == FALSE) {
- flush();
- switch (c = getchar()) {
- case '\b' : /* Erase previous char */
- if (ptr > inbuf) {
- ptr--;
-#ifdef UNIX
- tputs(SE, 0, _putchar);
-#else
- string_print(normal_video);
-#endif /* UNIX */
- if (is_tab(*ptr))
- string_print(" \b\b\b \b\b");
- else
- string_print(" \b\b \b");
-#ifdef UNIX
- tputs(SO, 0, _putchar);
-#else
- string_print(rev_video);
-#endif /* UNIX */
- string_print(" \b");
- *ptr = '\0';
- }
- else
- ring_bell();
- break;
- case '\n' : /* End of input */
- /* If inbuf is empty clear status_line */
- return (ptr == inbuf && clearfl == TRUE) ? NO_INPUT :FINE;
- default : /* Only read ASCII chars */
- if ((c >= ' ' && c <= '~') || c == '\t') {
- *ptr++ = c;
- *ptr = '\0';
- if (c == '\t')
- string_print("^I");
- else
- putchar(c);
- string_print(" \b");
- }
- else
- ring_bell();
- }
- }
- quit = FALSE;
- return ERRORS;
-}
-
-/*
- * Get_file() reads a filename from the terminal. Filenames longer than
- * FILE_LENGHT chars are truncated.
- */
-int get_file(message, file)
-char *message, *file;
-{
- char *ptr;
- int ret;
-
- if (message == NIL_PTR || (ret = get_string(message, file, TRUE)) == FINE) {
- if (length_of((ptr = basename(file))) > NAME_MAX)
- ptr[NAME_MAX] = '\0';
- }
- return ret;
-}
-
-/* ======================================================================== *
- * UNIX I/O Routines *
- * ======================================================================== */
-
-#ifdef UNIX
-#undef putchar
-
-int _getchar()
-{
- char c;
-
- if (read(input_fd, &c, 1) != 1 && quit == FALSE)
- panic ("Cannot read 1 byte from input");
- return c & 0377;
-}
-
-void _flush()
-{
- (void) fflush(stdout);
-}
-
-void _putchar(c)
-char c;
-{
- (void) write_char(STD_OUT, c);
-}
-
-void get_term()
-{
- static char termbuf[50];
- extern char *tgetstr(), *getenv();
- char *loc = termbuf;
- char entry[1024];
-
- if (tgetent(entry, getenv("TERM")) <= 0) {
- printf("Unknown terminal.\n");
- exit(1);
- }
-
- AL = tgetstr("al", &loc);
- CE = tgetstr("ce", &loc);
- VS = tgetstr("vs", &loc);
- CL = tgetstr("cl", &loc);
- SO = tgetstr("so", &loc);
- SE = tgetstr("se", &loc);
- CM = tgetstr("cm", &loc);
- ymax = tgetnum("li") - 1;
- screenmax = ymax - 1;
-
- if (!CE || !SO || !SE || !CL || !AL || !CM) {
- printf("Sorry, no mined on this type of terminal\n");
- exit(1);
- }
-}
-#endif /* UNIX */
diff --git a/languages/cprogs/mygetchar.c b/languages/cprogs/mygetchar.c
deleted file mode 100644
index 48ccdcde..00000000
--- a/languages/cprogs/mygetchar.c
+++ /dev/null
@@ -1,20 +0,0 @@
-#include
-
-int mygetchar(void);
-
-int main(void)
-{
- int c;
- c = mygetchar();
-
- printf("%c",c);
-
- return 0;
-}
-
-int mygetchar(void)
-{
- char c;
- return (read(0,&c,1)==1)?(unsigned char)c:EOF;
-}
-
diff --git a/languages/cprogs/numlinesort.c b/languages/cprogs/numlinesort.c
deleted file mode 100644
index fd732641..00000000
--- a/languages/cprogs/numlinesort.c
+++ /dev/null
@@ -1,166 +0,0 @@
-/* Sorting program, with a provision of sorting lines numerically as well */
-#include
-#include
-#define MAXLINES 5000 /* maximum number of lines to be sorted */
-char *lineptr[MAXLINES]; /* pointers to text lines */
-
-int readlines(char *lineptr[],int nlines);
-void writelines(char *lineptr[],int nlines);
-
-void myqsort(void *lineptr[],int left,int right,int (*comp)(void *,void *));
-
-int numcmp(char *,char *);
-
-/* sort input lines */
-
-int main(int argc,char *argv[])
-{
- int nlines; /* number of input lines read */
- int numeric = 0; /* if numeric sort */
-
- if( argc > 1 && strcmp(argv[1],"-n") == 0)
- numeric = 1;
- if( (nlines = readlines(lineptr,MAXLINES)) >= 0)
- {
- myqsort((void **)lineptr,0,nlines -1,(int (*)(void *,void *))(numeric ? numcmp:strcmp));
- writelines(lineptr,nlines);
- return 0;
- }
- else
- {
- printf("input too big to sort \n");
- return 1;
- }
-}
-
-/* myqsort: sort v[left] .. v[right] into increasing order */
-
-void myqsort(void *v[],int left,int right,int (*comp)(void *,void *))
-{
- int i,last;
- void swap(void *v[],int,int);
- if(left >= right) /* do nothing if array contains fewer than two elements */
- return;
-
- swap(v,left,(left+right)/2);
- last = left;
-
- for(i = left + 1; i <= right; i++)
- if((*comp)(v[i],v[left])<0)
- swap(v,++last,i);
-
- swap(v,left,last);
- myqsort(v,left,last-1,comp);
- myqsort(v,last+1,right,comp);
-}
-
-#include
-
-/* numcmp: compare s1 and s2 numerically */
-
-int numcmp(char *s1,char *s2)
-{
- double v1,v2;
- v1 = atof(s1);
- v2 = atof(s2);
-
- if( v1 < v2 )
- return -1;
- else if ( v1 > v2)
- return 1;
- else
- return 0;
-}
-
-void swap(void *v[],int i,int j)
-{
- void *temp;
- temp = v[i];
- v[i] = v[j];
- v[j] = temp;
-}
-
-/* for realines and writelines */
-
-#define MAXLEN 1000
-
-int getline(char *,int);
-char *alloc(int);
-
-/* readlines: read input line */
-
-int readlines(char *lineptr[],int maxlines)
-{
- int len,nlines;
- char *p,line[MAXLEN];
-
- nlines = 0;
-
- while((len=getline(line,MAXLEN)) > 0)
- if(nlines >= maxlines || (p=alloc(len)) == NULL)
- return -1;
- else
- {
- line[len-1] = '\0'; /* delete newline */
- strcpy(p,line);
- lineptr[nlines++] = p;
- }
- return nlines;
-}
-
-/* writelines: write output line */
-
-void writelines(char *lineptr[],int nlines)
-{
- int i;
- for(i =0;i < nlines;i++)
- printf("%s\n",lineptr[i]);
-}
-
-
-/* for *alloc(int) */
-
-#define ALLOCSIZE 10000
-
-static char allocbuf[ALLOCSIZE];
-static char *allocp = allocbuf;
-
-char *alloc(int n)
-{
- if(allocbuf + ALLOCSIZE - allocp >= n)
- {
- allocp += n;
- return allocp -n;
- }
- else
- return 0;
-}
-
-void afree(char *p)
-{
- if(p >= allocbuf && p < allocbuf + ALLOCSIZE)
- allocp = p;
-}
-
-
-
-/* getline: read a line into s and return its length */
-
-int getline(char s[],int lim)
-{
- int c,i;
-
- for(i=0;i
-/* echo: command line arguments; 1st version */
-
-int main(int argc,char *argv[])
-{
- int i;
-
- for( i = 1 ; i < argc ;i++ )
- printf("%s %s",argv[i],(i < argc -1)? " ": "");
- printf("\n");
- return 0;
-}
-
-
diff --git a/languages/cprogs/pgechov2.c b/languages/cprogs/pgechov2.c
deleted file mode 100644
index 0c7be6ca..00000000
--- a/languages/cprogs/pgechov2.c
+++ /dev/null
@@ -1,10 +0,0 @@
-#include
-/* echo command-line arguments: 2nd version */
-int main(int argc,char *argv[])
-{
- while(--argc > 0)
- printf("%s %s",*++argv,(argc > 1)? " ": "");
- printf("\n");
- return 0;
-}
-
diff --git a/languages/cprogs/pgechov3.c b/languages/cprogs/pgechov3.c
deleted file mode 100644
index bb1c53d2..00000000
--- a/languages/cprogs/pgechov3.c
+++ /dev/null
@@ -1,9 +0,0 @@
-#include
-/*echo command - line arguments: 3rd version */
-int main(int argc,char *argv[])
-{
- while( --argc >0)
- printf((argc > 1)?"%s ":"%s",*++argv);
- printf("\n");
-}
-
diff --git a/languages/cprogs/prepro1.c b/languages/cprogs/prepro1.c
deleted file mode 100644
index d944f2be..00000000
--- a/languages/cprogs/prepro1.c
+++ /dev/null
@@ -1,14 +0,0 @@
-/* # operator in preprocessor */
-#include
-
-#define dprint(expr) printf(#expr " = %d \n",expr);
-
-int main(void)
-{
- int x=10,y=5;
-
- dprint(x/y);
-
- return 0;
-}
-
diff --git a/languages/cprogs/prepro2.c b/languages/cprogs/prepro2.c
deleted file mode 100644
index 79ddd243..00000000
--- a/languages/cprogs/prepro2.c
+++ /dev/null
@@ -1,14 +0,0 @@
-/* ## preprocessor operator */
-
-#include
-
-#define paste(front,back) front ## back
-
-int main(void)
-{
- int i=paste(10,50);
- printf("%d",i);
-
- return 0;
-}
-
diff --git a/languages/cprogs/printd.c b/languages/cprogs/printd.c
deleted file mode 100644
index ae71b154..00000000
--- a/languages/cprogs/printd.c
+++ /dev/null
@@ -1,30 +0,0 @@
-/* Recursion example; consider printing a number as a character string */
-
-#include
-
-void printd(int n);
-
-int main(void)
-{
- int n;
- n = 15000;
-
- printd(n);
-
- return 0;
-}
-
-void printd(int n)
-{
- if(n < 0)
- {
- putchar('-');
- n = -n;
- }
- if(n / 10)
- printd(n/10);
-
- putchar(n%10+'0');
-}
-
-
diff --git a/languages/cprogs/quicksort.c b/languages/cprogs/quicksort.c
deleted file mode 100644
index a71a482f..00000000
--- a/languages/cprogs/quicksort.c
+++ /dev/null
@@ -1,64 +0,0 @@
-/* quicksort: example of recursive sorting
- Developed by C.A.R. Hoare in 1962. Given an array,one element is chosen and the others are
- partitioned into two subsets - those less than the partition element and those greater than or
- equal to it. The same process is then applied recursively to the two subsets. When a subset has fewer than two elements, it does not need any sorting; this stops the recursion */
-
-#include
-
-void qsort(int v[],int left,int right);
-void swap(int v[],int i,int j);
-
-int main(void)
-{
- int i,left,right,v[10]={43,53,12,64,15,67,87,10,6,90};
- left=0;
- right=9;
-
- printf("Unsorted Array\n");
- for(i=0;i<=9;++i)
- printf(" %d",v[i]);
- qsort(v,left,right);
-
- printf("\nSorted Array\n");
- for(i=0;i<=9;++i)
- printf(" %d",v[i]);
-
- return 0;
-}
-
-void qsort(int v[],int left,int right)
-{
- int i,last;
-
- if(left>=right)
- return;
-
- swap(v,left,(left+right)/2);
-
- last=left;
-
- for(i=left+1;i<=right;i++)
- if(v[i] < v[left])
- swap(v,++last,i);
- swap(v,left,last);
-
- qsort(v,left,last-1);
-
- qsort(v,last+1,right);
-}
-
-/* swap: interchange v[i] and v[j] */
-
-void swap(int v[],int i,int j)
-{
- int temp;
-
- temp = v[i];
-
- v[i] = v[j];
-
- v[j] = temp;
-}
-
-
-
diff --git a/languages/cprogs/rot13.c b/languages/cprogs/rot13.c
deleted file mode 100644
index e80a5615..00000000
--- a/languages/cprogs/rot13.c
+++ /dev/null
@@ -1,38 +0,0 @@
-/* rot13 algorithm. Very Simple and Interesting */
-
-#include
-#define ROT 13
-
-int main(void)
-{
- int c,e;
-
- while((c=getchar())!=EOF)
- {
- if(c >='A' && c <='Z')
- {
- if((e = c + ROT) <= 'Z')
- putchar(e);
- else
- {
- e = c - ROT;
- putchar(e);
- }
- }
- else if(c >='a' && c <='z')
- {
- if((e= c + ROT) <= 'z')
- putchar(e);
- else
- {
- e = c - ROT;
- putchar(e);
- }
- }
- else
- putchar(c);
- }
-
-return 0;
-}
-
diff --git a/languages/cprogs/sample_template.c b/languages/cprogs/sample_template.c
deleted file mode 100644
index 89dda472..00000000
--- a/languages/cprogs/sample_template.c
+++ /dev/null
@@ -1,5 +0,0 @@
-#include
-
-int main(int argc, char *argv[]) {
- printf("This program needs to be replaced.");
-}
\ No newline at end of file
diff --git a/languages/cprogs/sec_1.1_helloworld.c b/languages/cprogs/sec_1.1_helloworld.c
index d677797d..a91aefbf 100644
--- a/languages/cprogs/sec_1.1_helloworld.c
+++ b/languages/cprogs/sec_1.1_helloworld.c
@@ -1,8 +1,8 @@
-/* First Program in KandR, the hello,world */
+/* First Program in K&R. print hello,world */
-#include
-void main()
+#include
+
+int main()
{
- printf("hello,world\n");
+ printf("hello, world\n");
}
-
diff --git a/languages/cprogs/sec_8.3_open_creat.c b/languages/cprogs/sec_8.3_open_creat.c
index 759ce34c..96f684ae 100644
--- a/languages/cprogs/sec_8.3_open_creat.c
+++ b/languages/cprogs/sec_8.3_open_creat.c
@@ -2,7 +2,7 @@
#include
#include
#include
-#include
+#include
#define PERMS 0666 /* RW for owner, group and others */
diff --git a/languages/cprogs/sec_8_2_read_write.c b/languages/cprogs/sec_8_2_read_write.c
index 9d9e7151..42f96345 100644
--- a/languages/cprogs/sec_8_2_read_write.c
+++ b/languages/cprogs/sec_8_2_read_write.c
@@ -1,8 +1,6 @@
/*copy input to output */
#include
-#include
-
#define BUFSIZ 1024
int main() /* copy input to output */
diff --git a/languages/cprogs/shellsort.c b/languages/cprogs/shellsort.c
deleted file mode 100644
index 7356da4d..00000000
--- a/languages/cprogs/shellsort.c
+++ /dev/null
@@ -1,39 +0,0 @@
-#include
-#include
-
-static void shell_sort(int a[], int size)
-{
- int i, j;
- int h=1;
- do {
- h = h * 3 + 1;
- }while (h <= size);
- do {
- h /= 3;
- for (i = h; i < size; i++)
- {
- int v = a[i];
- for (j = i; j >= h && a[j - h] > v; j -= h)
- a[j] = a[j -h];
- if (i != j)
- a[j] = v;
- }
- }while (h != 1);
-}
-
-int main(int argc, char *argv[])
-{
- int *a;
- int i;
-
- a = (int *)malloc((argc - 1) * sizeof(int));
- for (i = 0; i < argc - 1; i++)
- a[i] = atoi(argv[i+1]);
- shell_sort(a, argc);
-
- for (i = 0; i < argc -1; i++)
- printf("%d", a[i]);
- printf("\n");
- free(a);
- return 0;
-}
diff --git a/languages/cprogs/sizeof_various.c b/languages/cprogs/sizeof_various.c
deleted file mode 100644
index ba9dfb6b..00000000
--- a/languages/cprogs/sizeof_various.c
+++ /dev/null
@@ -1,12 +0,0 @@
-
-#include
-int main(int argc, char *argv[])
-{
- int i=10;
- char c='a';
- float j=1.0;
- printf("The size of int is %zu\n", sizeof i);
- printf("The size of char is %zu\n", sizeof c);
- printf("The size of float is %zu\n", sizeof j);
-}
-
diff --git a/languages/cprogs/sort.c b/languages/cprogs/sort.c
deleted file mode 100644
index 65d70bff..00000000
--- a/languages/cprogs/sort.c
+++ /dev/null
@@ -1,125 +0,0 @@
-#include
-#include
-
-#define MAXLINES 5000 /* max #lines to be sorted */
-
-char *lineptr[MAXLINES];
-
-int readlines(char *lineptr[],int nlines);
-void writelines(char *lineptr[],int nlines);
-
-void qsort(char *lineptr[],int left,int right);
-
-/* sort input lines */
-
-int main(void)
-{
- int nlines; /* number of input lines read */
-
- if((nlines = readlines(lineptr,MAXLINES)) >= 0)
- {
- qsort(lineptr,0,nlines-1);
- writelines(lineptr,nlines);
- return 0;
- }
- else
- {
- printf("error: input too big to sort \n");
- return 1;
- }
-}
-
-#define MAXLEN 1000 /* max length of any input line */
-int getline(char *,int);
-char *alloc(int);
-
-/* readlines: read input lines */
-int readlines(char *lineptr[],int maxlines)
-{
- int len,nlines;
- char *p,line[MAXLEN];
-
- nlines=0;
-
- while((len=getline(line,MAXLEN)) > 0)
- if(nlines >= maxlines || (p=alloc(len)) == NULL)
- return -1;
- else
- {
- line[len-1] = '\0';
- strcpy(p,line);
- lineptr[nlines++]=p;
- }
- return nlines;
-}
-
-/* writelines: write output lines */
-void writelines(char *lineptr[],int nlines)
-{
- int i;
- for(i=0;i= right)
- return;
- swap(v,left,(left+right)/2);
-
- last = left;
-
- for(i=left+1;i<=right;i++)
- if(strcmp(v[i],v[left])<0)
- swap(v,++last,i);
- swap(v,left,last);
- qsort(v,left,last-1);
- qsort(v,last+1,right);
-}
-
-/* swap: interchange v[i] and v[j] */
-
-void swap(char *v[],int i,int j)
-{
- char *temp;
-
- temp=v[i];
- v[i]=v[j];
- v[j]=temp;
-}
-
-#define ALLOCSIZE 10000 /* size of available space */
-
-static char allocbuf[ALLOCSIZE]; /* storage for alloc */
-static char *allocp = allocbuf; /* next free position */
-
-char *alloc(int n) /* return pointer to n characters */
-{
- if(allocbuf + ALLOCSIZE - allocp >= n)
- {
- allocp += n;
- return allocp -n;
- }
- else
- return 0;
-}
-
-int getline(char *s,int lim)
-{
- int c;
- char *t=s;
-
- while(--lim >0 && (c=getchar())!=EOF && c!='\n')
- *s++ = c;
- if( c == '\n')
- *s++ = c;
-
- *s= '\0';
-
- return s-t;
-}
-
diff --git a/languages/cprogs/sortv2.c b/languages/cprogs/sortv2.c
deleted file mode 100644
index 11e10323..00000000
--- a/languages/cprogs/sortv2.c
+++ /dev/null
@@ -1,131 +0,0 @@
-#include
-#include
-
-#define MAXLINES 5000 /* max #lines to be sorted */
-
-char *lineptr[MAXLINES];
-char linestor[MAXLINES];
-
-int readlines(char *lineptr[],char *linestor,int nlines);
-void writelines(char *lineptr[],int nlines);
-
-void qsort(char *lineptr[],int left,int right);
-
-/* sort input lines */
-
-int main(void)
-{
- int nlines; /* number of input lines read */
-
- if((nlines = readlines(lineptr,linestor,MAXLINES)) >= 0)
- {
- qsort(lineptr,0,nlines-1);
- writelines(lineptr,nlines);
- return 0;
- }
- else
- {
- printf("error: input too big to sort \n");
- return 1;
- }
-}
-
-#define MAXLEN 1000 /* max length of any input line */
-#define MAXSTOR 5000
-
-int getline(char *,int);
-char *alloc(int);
-
-/* readlines: read input lines */
-int readlines(char *lineptr[],char *linestor,int maxlines)
-{
- int len,nlines;
- char line[MAXLEN];
- char *p = linestor;
- char *linestop = linestor + MAXSTOR;
-
- nlines=0;
-
- while((len=getline(line,MAXLEN)) > 0)
- if(nlines >= maxlines || p+len > linestop)
- return -1;
- else
- {
- line[len-1] = '\0';
- strcpy(p,line);
- lineptr[nlines++]=p;
- p+=len;
- }
- return nlines;
-}
-
-/* writelines: write output lines */
-void writelines(char *lineptr[],int nlines)
-{
- int i;
- for(i=0;i= right)
- return;
- swap(v,left,(left+right)/2);
-
- last = left;
-
- for(i=left+1;i<=right;i++)
- if(strcmp(v[i],v[left])<0)
- swap(v,++last,i);
- swap(v,left,last);
- qsort(v,left,last-1);
- qsort(v,last+1,right);
-}
-
-/* swap: interchange v[i] and v[j] */
-
-void swap(char *v[],int i,int j)
-{
- char *temp;
-
- temp=v[i];
- v[i]=v[j];
- v[j]=temp;
-}
-
-#define ALLOCSIZE 10000 /* size of available space */
-
-static char allocbuf[ALLOCSIZE]; /* storage for alloc */
-static char *allocp = allocbuf; /* next free position */
-
-char *alloc(int n) /* return pointer to n characters */
-{
- if(allocbuf + ALLOCSIZE - allocp >= n)
- {
- allocp += n;
- return allocp -n;
- }
- else
- return 0;
-}
-
-int getline(char *s,int lim)
-{
- int c;
- char *t=s;
-
- while(--lim >0 && (c=getchar())!=EOF && c!='\n')
- *s++ = c;
- if( c == '\n')
- *s++ = c;
-
- *s= '\0';
-
- return s-t;
-}
-
diff --git a/languages/cprogs/squeezesc.c b/languages/cprogs/squeezesc.c
deleted file mode 100644
index 2bb67e0b..00000000
--- a/languages/cprogs/squeezesc.c
+++ /dev/null
@@ -1,48 +0,0 @@
-/* function squeeze: deletes all the c from s */
-
-#include
-#define MAXLINE 1000
-
-void squeeze(char s[],int c);
-int mgetline(char line[],int maxline);
-
-int main(void)
-{
- char line[MAXLINE];
- int c;
-
- mgetline(line,MAXLINE);
-
- putchar('#');
- c=getchar();
-
- squeeze(line,c);
-
- printf("%s",line);
-
- return 0;
-}
-
-int mgetline(char s[],int lim)
-{
- int i,c;
-
- for(i=0;i
-int strindex(char *s,char *t);
-
-int main(void)
-{
- char *s="This is a line";
- char *t="is";
- int ret;
-
- ret=strindex(s,t);
- printf("%d",ret);
-
- return 0;
-}
-
-int strindex(char *s,char *t)
-{
- char *b=s;
- char *p,*r;
-
- for(;*s!='\0';s++)
- {
- for(p=s,r=t;*r!='\0' && *p==*r;p++,r++)
- ;
-
- if(r>t && *r == '\0')
- return s-b;
- }
- return -1;
-}
diff --git a/languages/cprogs/system-programming/prog1.c b/languages/cprogs/system-programming/prog1.c
deleted file mode 100644
index 773a9599..00000000
--- a/languages/cprogs/system-programming/prog1.c
+++ /dev/null
@@ -1,15 +0,0 @@
-/**
- *
- * Program Description: System Programming Demonstration.
- *
- * Activity 0: http://cs-education.github.io/sys/#/chapter/0/section/0/activity/0
- *
- *
- * Date: 6/24/18
- **/
-
-int write(int, char *, int);
-
-int main(int argc, char *argv[]) {
- write(1, "Hello\n", 6);
-}
diff --git a/languages/cprogs/system-programming/prog2.c b/languages/cprogs/system-programming/prog2.c
deleted file mode 100644
index 97106557..00000000
--- a/languages/cprogs/system-programming/prog2.c
+++ /dev/null
@@ -1,13 +0,0 @@
-/**
- *
- * Program Description: write system call
- *
- * Date: 6/24/18
- **/
-
-#include
-
-int main(int argc, char *argv[]) {
- write(1, "Hello\n", 6);
- write(1, "World\n", 6);
-}
diff --git a/languages/cprogs/system-programming/system-programming-exercises.rst b/languages/cprogs/system-programming/system-programming-exercises.rst
deleted file mode 100644
index 864d42a6..00000000
--- a/languages/cprogs/system-programming/system-programming-exercises.rst
+++ /dev/null
@@ -1,4 +0,0 @@
-Programs
-========
-
-* * http://cs-education.github.io/sys/#/chapter/0/section/0/activity/0
diff --git a/languages/cprogs/test_post.py b/languages/cprogs/test_post.py
deleted file mode 100644
index d410442a..00000000
--- a/languages/cprogs/test_post.py
+++ /dev/null
@@ -1,28 +0,0 @@
-import urllib
-import urllib2
-url = 'http://codepad.org'
-
-#with open('helloworld.c') as fd:
-# code = fd.read()
-
-code = "print"
-
-values = {'lang' : 'Python',
- 'code' : code,
- 'submit':'Submit'}
-data = urllib.urlencode(values)
-
-print data
-
-#response = urllib2.urlopen(url, data)
-#the_page = response.geturl()
-#print the_page + '/fork'
-"""
-for href in the_page.split(""):
- if "Link:" in href:
- ind=href.index('Link:')
- found = href[ind+5:]
- for i in found.split('">'):
- if '
-#define MAXLINE 1000
-
-void unescape(char s[],char t[]);
-int getline(char line[],int maxlimit);
-
-int main(void)
-{
- char s[MAXLINE],t[MAXLINE];
-
- getline(t,MAXLINE);
-
- unescape(s,t);
-
- printf("%s",s);
-
- return 0;
-}
-
-void unescape(char s[],char t[])
-{
- int i,j;
-
- for(i=j=0;t[i]!='\0';++i)
- switch(t[i])
- {
- case '\\':
- switch(t[++i])
- {
- case 'n':
- s[j++]='\n';
- break;
- case 't':
- s[j++]='\t';
- break;
- default:
- s[j++]='\\';
- s[j++]=t[i];
- break;
- }
- break;
- default:
- s[j++]=t[i];
- break;
- }
- s[j]='\0';
-}
-
-int getline(char s[],int lim)
-{
- int i,c;
-
- for(i=0;i
-
-std=c99 for long long int types.
-
-Program written under
-Hardware Name: i686
-Processor: i686
-Hardware Platform:i386
-*/
-
-#include
-#include
-
-int main(void)
-{
- printf("Minimum value - Singed Char : %d\n",SCHAR_MIN);
- printf("Maximum value - Signed Char : %d\n",SCHAR_MAX);
- printf("Maximum value - Unsigned Char : %d\n",UCHAR_MAX);
-
- printf("Minimum value - Signed Short Int : %d\n",SHRT_MIN);
- printf("Maximum value - Signed Short Int : %d\n",SHRT_MAX);
- printf("Maximum value - Unsigned Short Int : %d\n",USHRT_MAX);
-
- printf("Minimum value - Signed Int : %d\n",INT_MIN);
- printf("Maximum value - Signed Int : %d\n",INT_MAX);
- printf("Maximum value - Unsigned Int : %u\n",UINT_MAX);
-
- printf("Minimum value - Signed long int : %ld\n",LONG_MIN);
- printf("Maximum value - Signed long int : %ld\n",LONG_MAX);
- printf("Maximum value - Unsigned long int : %lu\n",ULONG_MAX);
-
- printf("Minimum value - Signed long long int: %lld\n",LLONG_MIN);
- printf("Maximum value - Signed long long int: %lld\n",LLONG_MAX);
- printf("Maximum value - Unsigned long long int : %llu\n",ULLONG_MAX);
-
- return 0;
-}
diff --git a/languages/cprogs/wumpus.c b/languages/cprogs/wumpus.c
deleted file mode 100644
index d247286b..00000000
--- a/languages/cprogs/wumpus.c
+++ /dev/null
@@ -1,315 +0,0 @@
-
-/* Hunt the Wumpus Game */
-#include
-#include
-
-/* Program Constants Defined here */
-#define MAPWIDTH 7
-#define MAPHEIGHT 7
-#define NUM_PITS 4
-
-/* Function Prototypes Defined here */
-
-void initMap(char [MAPWIDTH][MAPHEIGHT]);
-void printMap(char [MAPWIDTH][MAPHEIGHT]);
-int move(int,int,int,int,char [MAPWIDTH][MAPHEIGHT]);
-void smell(int,int,char [MAPWIDTH][MAPHEIGHT]);
-int shoot(int,int,int,int,int,char [MAPWIDTH][MAPHEIGHT]);
-
-int main(void)
-{
- int num_arrows = 3; /* Total Number of Arrows */
- char map[MAPWIDTH][MAPHEIGHT]; /* Map of Territory */
- int choice; /* Users Input Command */
- int x,y; /* Current Position of Player */
- int dx,dy; /* Change in Direction */
- int flag; /* Generic Error Flag */
- int action; /* Action 1: -> Move */
- /* Action 2: -> Shoot */
-
- int debug = 1;
-
- /* Intialize Map */
-
- srand(time(NULL));
- initMap(map);
-
- /* Place Player at Random Location */
- /* Make sure you dont place a Player on Wumpus or a in a Pit! */
-
- flag = 1;
- while(flag == 1)
- {
- x = (rand() % 5) + 1;
- y = (rand() % 5) + 1;
-
- if(map[x][y] == '.')
- {
- map[x][y] = '@';
- flag = 0;
- }
- }
-
- printf("Welcome to 'Hunt the Wumpus' \n");
-
- if(debug)
- printMap(map);
-
- smell(x,y,map);
-
- /* Keep prompting for user input */
- do
- {
- printf("Enter a Command: ");
- fflush(stdout);
- choice = getc(stdin);
- printf("\n");
-
- /* Clearing stdin manually */
- if(choice != '\n')
- while(getchar() != '\n')
- ; /* empty statement */
-
- switch(choice)
- {
- /* Movement options */
- case 'n':
- dx = 0;
- dy = -1;
- action = 1;
- break;
- case 's':
- dx = 0;
- dy = +1;
- action =1;
- break;
- case 'e':
- dx = +1;
- dy = 0;
- action =1;
- break;
- case 'w':
- dx = -1;
- dy = 0;
- action =1;
- break;
-
- /* Shoot Options */
-
- case 'N':
- dx = 0;
- dy = -1;
- action = 2;
- break;
- case 'S':
- dx = 0;
- dy = +1;
- action = 2;
- break;
- case 'E':
- dx = +1;
- dy = 0;
- action = 2;
- break;
- case 'W':
- dx = -1;
- dy = 0;
- action = 2;
- break;
-
- default:
- printf("You cannot do that!\n");
- action = 0;
- break;
-
- }
-
- /* Move Player */
-
- if(action == 1)
- {
- flag = move(x,y,dx,dy,map);
- if(flag == 1)
- {
- map[x][y] ='.';
- x = x + dx;
- y = y + dy;
- map[x][y]='@';
-
- }
- else if(flag == -1)
- break;
- }
-
- /* Shoot */
- else if(action == 2)
- {
- flag = shoot(num_arrows--,x,y,dx,dy,map);
- if(flag == -1)
- break;
- }
-
- if(debug)
- printMap(map);
- smell(x,y,map);
-}while(choice != 'Q' || choice !='q');
-
-printf("Press any key to exit..");
-getchar();
-
-return 0;
-}
-
-/* Intialize Map with randomly placed Pits and Randomly placed Wumpus */
-
-void initMap(char map[MAPWIDTH][MAPHEIGHT])
-{
- int i,j;
- int x,y;
-
- /* First create a Clean Slate */
-
- for(j=0;j 0)
- {
- printf("You shoot your arrow into the dark...\n");
-
- if(map[x][y] == 'W')
- {
- printf("\a You have slain a Wumpus!\n");
- return -1;
- }
- else
- {
- printf("And, you can hear it fall to the ground in the next room \n");
- return 0;
- }
- }
- else
- {
- printf("You dont have any more arrows!\n");
- return 0;
- }
-}
diff --git a/languages/java/AbstractClass.java b/languages/java/AbstractClass.java
deleted file mode 100644
index 03bd7c0e..00000000
--- a/languages/java/AbstractClass.java
+++ /dev/null
@@ -1,60 +0,0 @@
-/**
- * Example 27 - Abstract Classes, Subclasses, and Overriding
- */
-class AbstractClass {
-
- abstract class Vessel {
- double contents;
- abstract double capacity();
- void fill(double amount) {
- contents = Math.min(contents + amount, capacity());
- }
- }
-
- class Tank extends Vessel {
-
- double length, width, height;
-
- Tank(double length, double width, double height) {
- this.length = length;
- this.width = width;
- this.height = height;
- }
-
- double capacity() {
- return length * width * height;
- }
-
- public String toString() {
- return "tank (" + length + ", " + width + ", " + height + ")";
- }
- }
-
- class Cube extends Tank {
-
- Cube(double side) {
- super(side, side, side);
- }
-
- public String toString() {
- return "cube (" + length + ")";
- }
- }
-
- class Barrel extends Vessel {
- double radius, height;
-
- Barrel(double radius, double height) {
- this.radius = radius;
- this.height = height;
- }
-
- double capacity() {
- return height * Math.PI * radius * radius;
- }
-
- public String toString() {
- return "barrel (" + radius + ", " + height + ")";
- }
- }
-}
diff --git a/languages/java/AlignNumbers.java b/languages/java/AlignNumbers.java
deleted file mode 100644
index 4faa724e..00000000
--- a/languages/java/AlignNumbers.java
+++ /dev/null
@@ -1,14 +0,0 @@
-import java.util.Random;
-
-/**
- * Example 14 - Aligning Numbers in Columns using out.format
- */
-class AlignNumbers {
- public static void main(String[] args) {
- Random rnd = new Random();
- for (int i = 0; i < 3; i++)
- for (int j = 0; j <5; j++)
- System.out.format("%4d", rnd.nextInt(1000));
- System.out.format("%n");
- }
-}
diff --git a/languages/java/AligningStrings.java b/languages/java/AligningStrings.java
deleted file mode 100644
index 44d80293..00000000
--- a/languages/java/AligningStrings.java
+++ /dev/null
@@ -1,9 +0,0 @@
-/**
- * Example 13 - Aligning Strings Using String.format Method
- */
-class AligningStrings {
- public static void main(String[] args) {
- String res = String.format("|%1$s|%1$15s|%1$-15s|", "Uthcode");
- System.out.println(res);
- }
-}
diff --git a/languages/java/AllPathsTryCatchFinally.java b/languages/java/AllPathsTryCatchFinally.java
deleted file mode 100644
index 93e42d35..00000000
--- a/languages/java/AllPathsTryCatchFinally.java
+++ /dev/null
@@ -1,27 +0,0 @@
-/**
- * Example 90 - All Paths Through a try-catch-finally Statement
- */
-class AllPathsTryCatchFinally {
-
- public static void main(String[] args) throws Exception{
- System.out.println(m(Integer.parseInt(args[0])));
- }
-
- static String m(int a) throws Exception {
- try {
- System.out.println("try ...");
- if (a/100 == 2) return "returned from try";
- if (a/100 == 3) throw new Exception("thrown by try");
- if (a/100 == 4) throw new RuntimeException("thrown by a try");
- } catch (RuntimeException x) {
- System.out.println("catch ...");
- if (a/10%10 == 2) return "returned from catch";
- if (a/10%10 == 3) throw new Exception("thrown by catch");
- } finally {
- System.out.println("finally");
- if (a%10 == 2) return "returned from finally";
- if (a%10 == 3) throw new Exception("thrown by finally");
- }
- return "terminated normally with " + a;
- }
-}
diff --git a/languages/java/AnimatedCanvas.java b/languages/java/AnimatedCanvas.java
deleted file mode 100644
index 9b502f08..00000000
--- a/languages/java/AnimatedCanvas.java
+++ /dev/null
@@ -1,35 +0,0 @@
-import javax.swing.*;
-import java.awt.*;
-
-/**
- * Example 95 - Graphic Animation Using the Runnable Interface
- */
-class AnimatedCanvas extends Canvas implements Runnable{
-
- AnimatedCanvas() {
- Thread u = new Thread(this);
- u.start();
- }
-
- @Override
- public void run() {
- for(;;){
- try {
- Thread.sleep(100);
- } catch (InterruptedException e) {}
- repaint();
- }
- }
-
- public void paint(Graphics g) {
- g.drawString("Hello World", 200, 200);
- }
-
- public static void main(String[] args) {
- AnimatedCanvas animatedCanvas = new AnimatedCanvas();
- JFrame jp = new JFrame();
- jp.getContentPane().add(animatedCanvas, BorderLayout.CENTER);
- jp.setSize(new Dimension(500,500));
- jp.setVisible(true);
- }
-}
diff --git a/languages/java/ArithmeticOperators.java b/languages/java/ArithmeticOperators.java
deleted file mode 100644
index 340551a4..00000000
--- a/languages/java/ArithmeticOperators.java
+++ /dev/null
@@ -1,18 +0,0 @@
-/**
- * Example 45 - Arithmetic Operators
- */
-class ArithmeticOperators {
-
- public static void main(String[] args) {
- int max = 2147483647;
- int min = -2147483638;
- System.out.println(max+1);
- System.out.println(min-1);
- System.out.print(10 / 3);
- System.out.println(10/(-3));
- System.out.print(10 % 3);
- System.out.println(10%(-3));
- System.out.print((-10) % 3);
- System.out.println((-10) % (-3));
- }
-}
diff --git a/languages/java/ArrayAssignmentTypeCheck.java b/languages/java/ArrayAssignmentTypeCheck.java
deleted file mode 100644
index 8872b8cd..00000000
--- a/languages/java/ArrayAssignmentTypeCheck.java
+++ /dev/null
@@ -1,21 +0,0 @@
-/**
- * Example 19 - Array Element Assignment Type Check at Run-Time
- */
-public class ArrayAssignmentTypeCheck {
-
- public static void main(String[] args) {
- Number[] a = new Integer[10];
- Double d = new Double(3.14);
- Integer i = new Integer(117);
- Number n = i;
- a[0] = i;
- a[1] = n;
- // Results in a Runtime exception
- try {
- a[2] = d;
- } catch (ArrayStoreException e) {
- System.out.println("Caught an ArrayStoreException.");
- }
- }
-
-}
diff --git a/languages/java/AssignmentNoCopyObjects.java b/languages/java/AssignmentNoCopyObjects.java
deleted file mode 100644
index 39ca6fa4..00000000
--- a/languages/java/AssignmentNoCopyObjects.java
+++ /dev/null
@@ -1,35 +0,0 @@
-/**
- * Example 49 - Assignment Does Not Copy Objects
- */
-class AssignmentNoCopyObjects {
-
- static class Point {
- int x;
- int y;
-
- Point(int x, int y) {
- this.x = x;
- this.y = y;
- }
-
- void move(int x1, int y1) {
- x += x1;
- y += y1;
- }
-
- public String toString() {
- return "(" + x + ", " + y + ")";
- }
- }
-
- public static void main(String[] args) {
- // TODO: Senthil Kumaran decouple Point
- Point p1 = new Point(10, 20);
- System.out.println("p1 is " + p1);
- Point p2 = p1;
- p2.move(8, 8);
- System.out.println("p2 is " + p2);
- System.out.println("p1 is " + p1);
- }
-
-}
diff --git a/languages/java/AutoBoxingUnboxing.java b/languages/java/AutoBoxingUnboxing.java
deleted file mode 100644
index 487a37e3..00000000
--- a/languages/java/AutoBoxingUnboxing.java
+++ /dev/null
@@ -1,35 +0,0 @@
-/**
- * Example 3 Automatic Boxing and Unboxing
- */
-class AutoBoxingUnboxing {
-
- public static void main(String[] args) {
- Boolean bb1 = false, bb2 = !bb1; // Boxing to false, true
- Integer bi1 = 117;
- Double bd1 = 1.2;
- boolean b1 = bb1;
- if (bb1)
- System.out.println("Not true");
- int i1 = bi1 + 2;
- // short s = bi1;
- long l = bi1;
- Integer bi2 = bi1 + 2;
- Integer[] biarr = {2, 3, 5, 7, 11};
- int sum = 0;
- for(Integer bi: biarr)
- sum += bi;
- for(int i: biarr)
- sum += i;
- int i = 1934;
- Integer bi4 = i, bi5 = i;
-
- // Prints true true true flase; bi4 == bi5 is a reference comparison
- System.out.format("%b %b %b %b\n", i==i, bi4==i, i==bi5, bi4==bi5);
- Boolean bbn = null;
- // boolean b = bbn; // compiles Okay but will fail at runtime
- // if (bbn)
- // System.out.println("Not True");
- Integer bin = null;
- // Integer bi6 = bin + 2; // compiles Okay, but will fail at runtime
- }
-}
diff --git a/languages/java/BinaryOutput.java b/languages/java/BinaryOutput.java
deleted file mode 100644
index 5d5b3166..00000000
--- a/languages/java/BinaryOutput.java
+++ /dev/null
@@ -1,60 +0,0 @@
-import java.io.*;
-
-/**
- * Example 147 - Binary Input and Output of Primitive Data
- */
-class BinaryOutput {
-
- public static void main(String[] args) throws IOException {
- DataOutputStream daos = new DataOutputStream(new FileOutputStream("tmp1.dat"));
- writedata(daos);
- daos.close();
-
- DataInputStream dais = new DataInputStream(new FileInputStream("tmp1.dat"));
- readdata(dais);
-
- RandomAccessFile raf = new RandomAccessFile("tmp2.dat", "rw");
- writedata(raf);
- raf.seek(0);
- readdata(raf);
- }
-
- static void writedata(DataOutput out) throws IOException {
- out.writeBoolean(true);
- out.writeByte(120);
- out.writeBytes("foo");
- out.writeBytes("fo");
- out.writeChar('A');
- out.writeChars("foo");
- out.writeDouble(300.1);
- out.writeFloat(300.2F);
- out.writeInt(1234);
- out.writeLong(12345L);
- out.writeShort(32000);
- out.writeUTF("foo");
- out.writeByte(-1);
- out.writeShort(-1);
- }
-
- static void readdata(DataInput in) throws IOException {
- byte[] buf1 = new byte[3];
- System.out.print(in.readBoolean());
- System.out.print(" " + in.readByte());
- in.readFully(buf1);
- in.readFully(buf1, 0, 2);
- System.out.print(" " + in.readChar());
- System.out.print(" " + in.readChar() + in.readChar() + in.readChar());
- System.out.print(" " + in.readDouble());
- System.out.print(" " + in.readFloat());
- System.out.print(" " + in.readInt());
- System.out.print(" " + in.readLong());
- System.out.print(" " + in.readShort());
- System.out.print(" " + in.readUTF());
- System.out.print(" " + in.readUTF());
- System.out.print(" " + in.readUnsignedByte());
- System.out.print(" " + in.readUnsignedShort());
- System.out.println();
- }
-
-
-}
diff --git a/languages/java/BinarySearchSortedArray.java b/languages/java/BinarySearchSortedArray.java
deleted file mode 100644
index 965283fd..00000000
--- a/languages/java/BinarySearchSortedArray.java
+++ /dev/null
@@ -1,29 +0,0 @@
-/**
- * Example 73 - Binary Search of a Sorted Array using a While loop
- */
-public class BinarySearchSortedArray {
-
- public static int binarySearch(double[] arr, double x) {
- int a = 0, b = arr.length - 1;
-
- while (a <= b) { // Loop invariant: arr[a-1] < x < arr[b+1]
- int i = (a + b) / 2;
- if (arr[i] < x)
- a = i + 1;
- else if (arr[i] > x)
- b = i - 1;
- else
- return i; // because arr[i] == x
- }
- // Now a > b, in fact a = b+1 and b = a -1, and so arr[b] < x < arr[a]
- // TODO: Senthil Kumaran - Why ~a ?
- // return ~a;
- return -1;
- }
-
- public static void main(String[] args) {
- double[] arr = { 4, 5, 6, 7, 8, 10, 12, 14};
- System.out.println(binarySearch(arr, 6.0));
- System.out.println(binarySearch(arr, 9.0));
- }
-}
diff --git a/languages/java/BitwiseOperators.java b/languages/java/BitwiseOperators.java
deleted file mode 100644
index 72749205..00000000
--- a/languages/java/BitwiseOperators.java
+++ /dev/null
@@ -1,24 +0,0 @@
-/**
- * Example 47 - Bitwise Operators and Shift Operators
- */
-public class BitwiseOperators {
-
- static void println4(int n) {
- for (int i = 3; i >=0 ; i--) {
- System.out.println(n>>i & 1);
- }
- System.out.println();
- }
-
- public static void main(String[] args) throws Exception {
- int a = 0x3;
- int b = 0x5;
- println4(a);
- println4(b);
- println4(~a);
- println4(~b);
- println4(a & b);
- println4(a ^ b);
- println4(a | b);
- }
-}
diff --git a/languages/java/BlockStatements.java b/languages/java/BlockStatements.java
deleted file mode 100644
index 88228f23..00000000
--- a/languages/java/BlockStatements.java
+++ /dev/null
@@ -1,33 +0,0 @@
-/**
- * Example 61 - Block Statements
- */
-public class BlockStatements {
-
- public static void main(String[] args) {
- int offset = 10;
-
- class Pair {
- public final int fst, snd;
-
- Pair(int fst, int snd) {
- this.fst = fst;
- this.snd = snd;
- }
-
- public String toString() {
- return String.format("(%d, %d)", fst, snd);
- }
- }
-
- {
- Pair p1 = new Pair(10, 10+offset);
- System.out.println(p1);
- }
-
- {
- Pair p1 = new Pair(200, 300);
- System.out.println(p1);
- }
-
- }
-}
diff --git a/languages/java/BuildingConcordance.java b/languages/java/BuildingConcordance.java
deleted file mode 100644
index e8a752fc..00000000
--- a/languages/java/BuildingConcordance.java
+++ /dev/null
@@ -1,49 +0,0 @@
-import java.io.*;
-import java.util.SortedMap;
-import java.util.SortedSet;
-import java.util.TreeMap;
-import java.util.TreeSet;
-
-/**
- * Example 127 Building a Concordance
- */
-class BuildingConcordance {
-
- static SortedMap> buildIndex(String filename) throws IOException {
-
- Reader r = new BufferedReader(new FileReader(filename));
- StreamTokenizer stok = new StreamTokenizer(r);
- stok.quoteChar('"');
- stok.ordinaryChars('!', '/');
- stok.nextToken();
-
- SortedMap> index = new TreeMap>();
-
- while (stok.ttype != StreamTokenizer.TT_EOF) {
- if (stok.ttype == StreamTokenizer.TT_WORD) {
- SortedSet ts;
- if (index.containsKey(stok.sval))
- ts = index.get(stok.sval);
- else {
- ts = new TreeSet();
- index.put(stok.sval, ts);
- }
- ts.add(stok.lineno());
- }
- stok.nextToken();
- }
- return index;
- }
-
-
- public static void main(String[] args) {
- try {
- SortedMap> concord = buildIndex("WeekdayNametoNumberHashMap.java");
-
- for(String word: concord.keySet())
- System.out.println(word + concord.get(word).toString());
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
-}
diff --git a/languages/java/CallingNonOverloaded.java b/languages/java/CallingNonOverloaded.java
deleted file mode 100644
index 232f36ab..00000000
--- a/languages/java/CallingNonOverloaded.java
+++ /dev/null
@@ -1,60 +0,0 @@
-import java.util.ArrayList;
-
-/**
- * Example 56 - Calling Non Overloaded, Non Overridden Methods
- */
-class CallingNonOverloaded {
-
- static class SPoint {
- static ArrayList allpoints = new ArrayList();
- int x, y;
-
- SPoint(int x, int y) {
- allpoints.add(this);
- this.x = x;
- this.y = y;
- }
-
- void move(int dx, int dy) {
- x += dx;
- y += dy;
- }
-
- public String toString() {
- return "(" + x + ", " + y + ")";
- }
-
- int getIndex() {
- return allpoints.indexOf(this);
- }
-
- static int getSize() {
- return allpoints.size();
- }
-
- static SPoint getPoint(int i) {
- return allpoints.get(i);
- }
-
- }
-
- public static void main(String[] args) {
- System.out.println("Number of points created: " + SPoint.getSize());
- SPoint p = new SPoint(12, 123);
- SPoint q = new SPoint(200, 10);
- SPoint r = new SPoint(99, 12);
- SPoint s = p;
-
- // Interesting
- q = null;
-
- System.out.println("Number of points created: " + SPoint.getSize());
- // Bad Style
- System.out.println("Number of points created: " + q.getSize());
- System.out.println("r is point number" + r.getIndex());
- for (int i = 0; i < SPoint.getSize(); i++)
- System.out.println("SPoint number " + i + " is " + SPoint.getPoint(i));
- }
-
-
-}
diff --git a/languages/java/CallingOverloaded.java b/languages/java/CallingOverloaded.java
deleted file mode 100644
index 5bc8639e..00000000
--- a/languages/java/CallingOverloaded.java
+++ /dev/null
@@ -1,39 +0,0 @@
-/**
- * Example 58 - Calling Overloaded Methods
- */
-class CallingOverloaded {
- static class Access {
- private static int x;
- static class SI {
- private static int y = x; // Access private x from enclosing class
- }
-
- static void m() {
- int z = SI.y; // Access private y from nested class
- }
-
- double m(int i) {
- return i;
- }
- boolean m(boolean b) {
- return !b;
- }
-
- static double m(int x, int y) {
- return x + y + 1;
- }
-
- static double m(double x, double y) {
- return x + y + 3;
- }
- }
-
- public static void main(String[] args) {
- Access a = new Access();
- System.out.println(Access.m(10, 20));
- System.out.println(Access.m(10, 20.0));
- System.out.println(Access.m(10.0, 20));
- System.out.println(Access.m(10.0, 20.0));
- }
-
-}
diff --git a/languages/java/CallingOverriddenConstructor.java b/languages/java/CallingOverriddenConstructor.java
deleted file mode 100644
index 522cb9aa..00000000
--- a/languages/java/CallingOverriddenConstructor.java
+++ /dev/null
@@ -1,41 +0,0 @@
-/**
- * Example 60 - Calling Overridden Methods from a Constructor
- */
-
-class D1 {
- D1() {
- m2();
- }
-
- void m1() {
- System.out.println("D1.m1");
- }
-
- void m2() {
- System.out.println("D1.m2");
- m1();
- }
-}
-
-class D2 extends D1 {
- int f;
- D2() {
- f = 7;
- }
-
- void m1() {
- System.out.println("D2.m1: " + f);
- }
-}
-
-class CallingOverriddenConstructor {
- public static void main(String[] args) {
- D2 d2 = new D2();
- D1 d1 = new D1();
- d2.m1();
- d2.m2();
- d1.m1();
- d1.m2();
- }
-
-}
diff --git a/languages/java/CallingOverriden.java b/languages/java/CallingOverriden.java
deleted file mode 100644
index 247ba183..00000000
--- a/languages/java/CallingOverriden.java
+++ /dev/null
@@ -1,58 +0,0 @@
-/**
- * Example 59 - Calling Overridden and Overloaded Methods
- */
-class C1 {
- static void m1(double d) {
- System.out.println("11d");
- }
- void m1(int i) {
- System.out.println("11i");
- }
- void m2(int i) {
- System.out.println("12i");
- }
-}
-
-class C2 extends C1 {
- static void m1(double d) {
- System.out.println("21d");
- }
-
- void m1(int i) {
- System.out.println("21i");
- }
-
- void m2(double d) {
- System.out.println("22d");
- }
-
- void m2(Integer ii) {
- System.out.println("22ii");
- }
-
- void m3(int i) {
- System.out.println("23i");
- }
-
- void m4(Integer ii) {
- System.out.println("24ii");
- }
-
-}
-class CallingOverriden {
-
- public static void main(String[] args) {
- int i = 17;
- Integer ii = new Integer(i);
- double d = 17.0;
- C2 c2 = new C2();
- C1 c1 = c2;
- c1.m1(i); c2.m1(i); c1.m1(d); c2.m1(d);
- c1.m2(i);
- c2.m2(i);
- c2.m2(ii);
- c2.m3(ii);
- c2.m4(i);
- }
-
-}
diff --git a/languages/java/ClassesInterfaces.java b/languages/java/ClassesInterfaces.java
deleted file mode 100644
index bb48df3c..00000000
--- a/languages/java/ClassesInterfaces.java
+++ /dev/null
@@ -1,71 +0,0 @@
-/**
- * Example 86 - Classes Implementing Interfaces
- */
-
-import javax.swing.*;
-import java.applet.Applet;
-import java.awt.*;
-
-interface Colored { Color getColor();}
-interface Drawable { void draw(Graphics g);}
-interface ColoredDrawable extends Colored, Drawable {}
-
-class ColoredPoint extends Point implements Colored {
- Color c;
- ColoredPoint(int x, int y, Color c) {
- super(x, y);
- this.c = c;
- }
-
- @Override
- public Color getColor() {
- return c;
- }
-}
-
-class ColoredDrawablePoint extends ColoredPoint implements ColoredDrawable {
-
- ColoredDrawablePoint(int x, int y, Color c) {
- super(x, y, c);
- }
-
- @Override
- public void draw(Graphics g) {
- g.fillRect(x, y, 1, 1);
- }
-}
-
-class ColoredRectangle implements ColoredDrawable {
- int x1, x2, y1, y2;
- Color c;
-
- ColoredRectangle(int x1, int y1, int x2, int y2, Color c) {
- this.x1 = x1;
- this.y1 = y1;
- this.x2 = x2;
- this.y2 = y2;
- this.c = c;
- }
-
- public Color getColor() {
- return c;
- }
-
- public void draw(Graphics g) {
- g.drawRect(x1, y1, x2-x1, y2-y1);
- }
-}
-
-class ClassesInterfaces extends Applet{
-
- public static void main(String[] args) {
- JFrame jp1 = new JFrame();
- ColoredRectangle rect = new ColoredRectangle(10, 10, 30, 30, Color.BLACK);
- // TODO: Senthil Kumaran - Use Graphics object g.
- ClassesInterfaces c = new ClassesInterfaces();
- jp1.getContentPane().add(c, BorderLayout.CENTER);
- jp1.setVisible(true);
-
- }
-
-}
diff --git a/languages/java/Comments.java b/languages/java/Comments.java
deleted file mode 100644
index 7d1da2c3..00000000
--- a/languages/java/Comments.java
+++ /dev/null
@@ -1,14 +0,0 @@
-/**
- * Example 1 - Comments
- */
-class Comments {
- //This is single line comment
-
- /*
- This is a multi-line comment, which can span across lines.
- */
- public static void main(String[] arg) {
- int /* The delimited comment can extend over a part of the line */ x = 42;
- System.out.printf("%d",x);
- }
-}
diff --git a/languages/java/CompleteInputOutput.java b/languages/java/CompleteInputOutput.java
deleted file mode 100644
index 40c0ba00..00000000
--- a/languages/java/CompleteInputOutput.java
+++ /dev/null
@@ -1,21 +0,0 @@
-import java.io.BufferedReader;
-import java.io.IOException;
-import java.io.InputStreamReader;
-
-/**
- * Example 140 - A Complete Input-Output Example
- */
-class CompleteInputOutput {
-
- public static void main(String[] args) throws IOException {
- BufferedReader r = new BufferedReader(new InputStreamReader(System.in));
- int count = 0;
- String s = r.readLine();
- while (s != null & !s.equals("")) {
- count++;
- s = r.readLine();
- }
- System.out.println("You entered " + count + " non empty lines");
- }
-
-}
diff --git a/languages/java/CompoundAssignment.java b/languages/java/CompoundAssignment.java
deleted file mode 100644
index 771bbc1d..00000000
--- a/languages/java/CompoundAssignment.java
+++ /dev/null
@@ -1,18 +0,0 @@
-/**
- * Example 50 - Compound Assignment Operators
- */
-class CompoundAssignment {
-
- static double multiply(double[] xs) {
- double prod = 1.0;
- for (int i = 0; i < xs.length; i++) {
- prod *= xs[i];
- }
- return prod;
- }
-
- public static void main(String[] args) {
- double[] xs = {1.0, 2.0, 3.0};
- System.out.println(multiply(xs));
- }
-}
diff --git a/languages/java/ConcatCliArgs.java b/languages/java/ConcatCliArgs.java
deleted file mode 100644
index e007a361..00000000
--- a/languages/java/ConcatCliArgs.java
+++ /dev/null
@@ -1,11 +0,0 @@
-/**
- * Example 100 - Efficiently Concatenating All Command Line Arguments
- */
-class ConcatCliArgs {
- public static void main(String[] args) {
- StringBuilder res = new StringBuilder();
- for (int i = 0; i < args.length; i++)
- res.append(args[i]);
- System.out.println(res.toString());
- }
-}
diff --git a/languages/java/Concatenate.java b/languages/java/Concatenate.java
deleted file mode 100644
index cd6450b2..00000000
--- a/languages/java/Concatenate.java
+++ /dev/null
@@ -1,12 +0,0 @@
-/**
- * Example 9 Concatenating all Command Line Arguments.
- */
-
-class Concatenate {
- public static void main(String[] args) {
- String res = "";
- for(int i = 0; i < args.length; i++)
- res += args[i];
- System.out.println(res);
- }
-}
diff --git a/languages/java/ConcordanceUsingIterables.java b/languages/java/ConcordanceUsingIterables.java
deleted file mode 100644
index cac96dcc..00000000
--- a/languages/java/ConcordanceUsingIterables.java
+++ /dev/null
@@ -1,49 +0,0 @@
-import java.io.*;
-import java.util.*;
-
-/**
- * Example 130 - Printing a Concordance Using Iterables
- */
-class ConcordanceUsingIterables {
-
- static SortedMap> buildIndex(String filename) throws IOException {
-
- Reader r = new BufferedReader(new FileReader(filename));
- StreamTokenizer stok = new StreamTokenizer(r);
- stok.quoteChar('"');
- stok.ordinaryChars('!', '/');
- stok.nextToken();
-
- SortedMap> index = new TreeMap>();
-
- while (stok.ttype != StreamTokenizer.TT_EOF) {
- if (stok.ttype == StreamTokenizer.TT_WORD) {
- SortedSet ts;
- if (index.containsKey(stok.sval))
- ts = index.get(stok.sval);
- else {
- ts = new TreeSet();
- index.put(stok.sval, ts);
- }
- ts.add(stok.lineno());
- }
- stok.nextToken();
- }
- return index;
- }
-
- static void printIndex(SortedMap> index) {
- for (Map.Entry> entry: index.entrySet()) {
- System.out.print(entry.getKey() + ": ");
- SortedSet lineNoSet = entry.getValue();
- for (int lineno: lineNoSet)
- System.out.print(lineno + " ");
- System.out.println();
- }
- }
-
- public static void main(String[] args) throws IOException {
- SortedMap> concord = buildIndex("WeekdayNametoNumberHashMap.java");
- printIndex(concord);
- }
-}
diff --git a/languages/java/ConcreteCollection.java b/languages/java/ConcreteCollection.java
deleted file mode 100644
index 4d186e4e..00000000
--- a/languages/java/ConcreteCollection.java
+++ /dev/null
@@ -1,76 +0,0 @@
-import java.util.*;
-
-/**
- * Example 121 - Using the Concrete Collection and Map Classes
- */
-
-class ConcreteCollection {
- public static void main(String[] args) {
- List list1 = new LinkedList();
- list1.add("list");
- list1.add("dup");
- list1.add("x");
- list1.add("dup");
- traverse(list1);
-
- List list2 = new ArrayList();
- list2.add("list");
- list2.add("dup");
- list2.add("x");
- list2.add("dup");
- traverse(list2);
-
- Set set1 = new HashSet();
- set1.add("set");
- set1.add("dup");
- set1.add("x");
- set1.add("dup");
- traverse(set1);
-
- SortedSet set2 = new TreeSet();
- set2.add("set");
- set2.add("dup");
- set2.add("x");
- set2.add("dup");
- traverse(set2);
-
- LinkedHashSet set3 = new LinkedHashSet();
- set3.add("set");
- set3.add("dup");
- set3.add("x");
- set3.add("dup");
- traverse(set3);
-
- Map m1 = new HashMap();
- m1.put("map", "J");
- m1.put("dup", "K");
- m1.put("x", "M");
- m1.put("dup", "L");
- traverse(m1.keySet());
- traverse(m1.values());
-
- SortedMap m2 = new TreeMap();
- m2.put("map", "J");
- m2.put("dup", "K");
- m2.put("x", "M");
- m2.put("dup", "L");
- traverse(m2.keySet());
- traverse(m2.values());
-
- LinkedHashMap m3 = new LinkedHashMap();
- m3.put("map", "J");
- m3.put("dup", "K");
- m3.put("x", "M");
- m3.put("dup", "L");
- traverse(m3.keySet());
- traverse(m3.values());
-
- }
-
- static void traverse(Collection coll) {
- for(String elem: coll)
- System.out.print(elem + " ");
- System.out.println();
-
- }
-}
diff --git a/languages/java/ConditionalExpression.java b/languages/java/ConditionalExpression.java
deleted file mode 100644
index e97685aa..00000000
--- a/languages/java/ConditionalExpression.java
+++ /dev/null
@@ -1,15 +0,0 @@
-/**
- * Example 51 - Conditional Expression
- */
-public class ConditionalExpression {
-
- static double absolute(double x) {
- return (x >= 0 ? x : -x);
- }
-
- public static void main(String[] args) {
- Double x = 5.12;
- System.out.println(absolute(x));
- }
-
-}
diff --git a/languages/java/ConstraintsType.java b/languages/java/ConstraintsType.java
deleted file mode 100644
index 947abd1c..00000000
--- a/languages/java/ConstraintsType.java
+++ /dev/null
@@ -1,36 +0,0 @@
-import java.util.Date;
-
-/**
- * Example 110 - Constraints Involving Type Parameters
- */
-
-class ComparablePair, U extends Comparable>
- implements Comparable>
- {
-
- public final T fst;
- public final U snd;
-
- public ComparablePair(T fst, U snd) {
- this.fst = fst;
- this.snd = snd;
- }
-
- @Override
- public int compareTo(ComparablePair that) {
- int firstCmp = this.fst.compareTo(that.fst);
- return firstCmp != 0 ? firstCmp : this.snd.compareTo(that.snd);
- }
- }
-class ConstraintsType {
-
- public static void main(String[] args) {
- Date d = new Date(10);
- String s = "Senthil";
- ComparablePair p1 = new ComparablePair(s, d);
- ComparablePair p2 = new ComparablePair("Kumaran", new Date(11));
- ComparablePair p3 = new ComparablePair(s, d);
- System.out.println(p1.compareTo(p2));
- System.out.println(p1.compareTo(p3));
- }
-}
diff --git a/languages/java/ConstructorOverloading.java b/languages/java/ConstructorOverloading.java
deleted file mode 100644
index 5d768dc5..00000000
--- a/languages/java/ConstructorOverloading.java
+++ /dev/null
@@ -1,30 +0,0 @@
-/**
- * Example 36 - Constructor Overloading; Calling Another Constructor
- */
-class ConstructorOverloading {
- int x, y;
-
- ConstructorOverloading(int x, int y) {
- this.x = x;
- this.y = y;
- }
-
- ConstructorOverloading(ConstructorOverloading c) {
- this(c.x, c.y);
- }
-
- void incr(int x1, int y1) {
- x += x1;
- y += y1;
- }
-
- public String toString() {
- return "(" + x + ", " + y + ")";
- }
-
- public static void main(String[] args) {
- ConstructorOverloading c1 = new ConstructorOverloading(10, 20);
- c1.incr(40, 40);
- System.out.println(c1);
- }
-}
diff --git a/languages/java/ConversionPrimitive.java b/languages/java/ConversionPrimitive.java
deleted file mode 100644
index cd3256d9..00000000
--- a/languages/java/ConversionPrimitive.java
+++ /dev/null
@@ -1,25 +0,0 @@
-/**
- * Example 4 Conversion between Primitive Types
- *
- */
-class ConversionPrimitive {
- private static void floatdouble(float f, double d) {
- System.out.println(f + " " + d);
- }
- private static void bytecharshort(byte b, char c, short s) {
- System.out.println(b + " " + (int) c + " " + s);
- }
- private static void intint(int i1, int i2) {
- System.out.println(i1 + " " + i2);
- }
-
- public static void main(String[] args) {
- int i1 = 1000111222, i2 = 40000, i3 = -1;
- floatdouble(i1, i1);
- bytecharshort((byte)i2, (char)i2, (short)i2);
- bytecharshort((byte)i3, (char)i3, (short)i3);
- intint((int)1.9, (int)-1.9);
- intint((int)1.5, (int)-1.5);
- intint((int)2.5, (int)-2.5);
- }
-}
diff --git a/languages/java/CountEs.java b/languages/java/CountEs.java
deleted file mode 100644
index cb45c84f..00000000
--- a/languages/java/CountEs.java
+++ /dev/null
@@ -1,16 +0,0 @@
-/**
- * Example 10 Counting the Number of e's in a String.
- */
-class CountEs {
- static int ecount(String s) {
- int ecount = 0;
- for (int i=0; i < s.length(); i++)
- if (s.charAt(i) == 'e')
- ecount++;
- return ecount;
- }
-
- public static void main(String[] args) {
- System.out.println(CountEs.ecount("elepantine"));
- }
-}
diff --git a/languages/java/DeclaringCheckedException.java b/languages/java/DeclaringCheckedException.java
deleted file mode 100644
index 03323bdf..00000000
--- a/languages/java/DeclaringCheckedException.java
+++ /dev/null
@@ -1,28 +0,0 @@
-/**
- * Declaring a Checked Exception Class
- */
-
-class WeekdayException extends Exception {
- public WeekdayException(String wday) {
- super("Illegal weekday: " + wday);
- }
-}
-
-public class DeclaringCheckedException {
-
- static final String[] wdays =
- {"Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"};
-
-
- static int wdayno4(String wday) throws WeekdayException {
- for (int i = 0; i < wdays.length; i++)
- if (wday.equals(wdays[i]))
- return i + 1;
- throw new WeekdayException(wday);
- }
-
- public static void main(String[] args) throws WeekdayException {
- System.out.println(wdayno4("Monday"));
- System.out.println(wdayno4("Sommar"));
- }
-}
diff --git a/languages/java/Describe.java b/languages/java/Describe.java
deleted file mode 100644
index 0395b7e3..00000000
--- a/languages/java/Describe.java
+++ /dev/null
@@ -1,28 +0,0 @@
-public class Describe {
- static void describe(Class> clazz, String pad, String leadin) {
- if (clazz == null) return;
- String type =
- clazz.isInterface() ? "interface" :
- clazz.isArray() ? "array" :
- clazz.isPrimitive() ? "primitive" :
- clazz.isEnum() ? "enum" :
- "class";
- System.out.printf("%s%s%s %s ( %s )%n",
- pad, leadin, type, clazz.getSimpleName(), clazz.getName());
- for (Class> interfaze : clazz.getInterfaces()) {
- describe(interfaze, pad + " ", "implements ");
- }
- describe(clazz.getComponentType(), pad + " ", "elements are ");
- describe(clazz.getSuperclass(), pad + " ", "extends ");
-}
-static void describe(Class> clazz) {
- describe(clazz, "", "");
- System.out.println();
-}
-public static void main(String[] args) {
- describe(boolean[][].class);
- describe(java.math.RoundingMode.class);
- describe(java.util.ArrayList.class);
- describe(void.class);
-}
-}
diff --git a/languages/java/DoWhileRollaDie.java b/languages/java/DoWhileRollaDie.java
deleted file mode 100644
index b1066a60..00000000
--- a/languages/java/DoWhileRollaDie.java
+++ /dev/null
@@ -1,18 +0,0 @@
-/**
- * Example 75 - Using do-while to Roll a Die and Compute Sum Until 5 or 6 Comes up
- */
-class DoWhileRollaDie {
-
- public static void main(String[] args) {
- int sum = 0, eyes;
-
- do {
- eyes = (int) (1 + 6 * Math.random());
- sum += eyes;
- } while (eyes < 5);
-
- sum -= eyes; // remove the 5 added.
-
- System.out.println(sum);
- }
-}
diff --git a/languages/java/EmptyStatement.java b/languages/java/EmptyStatement.java
deleted file mode 100644
index 59579e82..00000000
--- a/languages/java/EmptyStatement.java
+++ /dev/null
@@ -1,13 +0,0 @@
-/**
- * Example 62 - Empty Statement and Infinite Loop Because of misplaced semicolon
- */
-public class EmptyStatement {
-
- public static void main(String[] args) {
-
- int i = 0;
- // misplaced semicolon; runs forver and ever.
- while(i < 10);
- i++;
- }
-}
diff --git a/languages/java/EnhancedForStatement.java b/languages/java/EnhancedForStatement.java
deleted file mode 100644
index 6fdb37ae..00000000
--- a/languages/java/EnhancedForStatement.java
+++ /dev/null
@@ -1,12 +0,0 @@
-/**
- * Example 69 - Enhanced for statement on an Array
- */
-public class EnhancedForStatement {
- public static void main(String[] args) {
- int[] arr = { 2, 3, 4, 5, 7, 11};
- int sum = 0;
- for(int i: arr)
- sum += i;
- System.out.println(sum);
- }
-}
diff --git a/languages/java/EqualityStrings.java b/languages/java/EqualityStrings.java
deleted file mode 100644
index ed4a5831..00000000
--- a/languages/java/EqualityStrings.java
+++ /dev/null
@@ -1,20 +0,0 @@
-/**
- * Example 7 Equality of Strings and the Subtlety of (+) Operator.
- */
-class EqualityStrings {
- public static void main(String[] args) {
- String s1 = "abc";
- String s2 = s1 + "";
- String s3 = s1;
- String s4 = s1.toString();
-
- System.out.println("s1 and s2 identical objects: " + (s1 == s2));
- System.out.println("s1 and s3 identical objects: " + (s1 == s3));
- System.out.println("s1 and s4 identical objects: " + (s1 == s4));
- System.out.println("s1 and s2 contain same text: " + (s1.equals(s2)));
- System.out.println("s1 and s3 contain same text: " + (s1.equals(s3)));
-
- System.out.println(10 + 25 + "A");
- System.out.println("A" + 10 + 25);
- }
-}
diff --git a/languages/java/EqualsMethod.java b/languages/java/EqualsMethod.java
deleted file mode 100644
index 42859e37..00000000
--- a/languages/java/EqualsMethod.java
+++ /dev/null
@@ -1,40 +0,0 @@
-/**
- * Example 134 - An equals Method for the Time Class
- */
-public class EqualsMethod {
-
- static class Time implements Comparable