Codebase list mdp-src / upstream/1.0.3
Imported Upstream version 1.0.3 Lev Lamberov 8 years ago
29 changed file(s) with 4185 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
0 set args -d sample.md
0 # temporary compile results
1 *.o
2
3 # Binary excutions
4 mdp
5 mdp.exe
6
7 # Other temporary files
8 .DS_Store
9 *~
10 *.swp
11 *.sublime-workspace
12 *.out
13 tags
0 Author: visit1985
1
2 Contributors:
3 Pyrohh
4 FreeBirdLjj
5 ungureanuvladvictor
6 lukaslueg
7 mattn
8 fredjean
9 hspak
10 dopsi
11 alx741
12 mnalt
13
0 GNU GENERAL PUBLIC LICENSE
1 Version 3, 29 June 2007
2
3 Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
4 Everyone is permitted to copy and distribute verbatim copies
5 of this license document, but changing it is not allowed.
6
7 Preamble
8
9 The GNU General Public License is a free, copyleft license for
10 software and other kinds of works.
11
12 The licenses for most software and other practical works are designed
13 to take away your freedom to share and change the works. By contrast,
14 the GNU General Public License is intended to guarantee your freedom to
15 share and change all versions of a program--to make sure it remains free
16 software for all its users. We, the Free Software Foundation, use the
17 GNU General Public License for most of our software; it applies also to
18 any other work released this way by its authors. You can apply it to
19 your programs, too.
20
21 When we speak of free software, we are referring to freedom, not
22 price. Our General Public Licenses are designed to make sure that you
23 have the freedom to distribute copies of free software (and charge for
24 them if you wish), that you receive source code or can get it if you
25 want it, that you can change the software or use pieces of it in new
26 free programs, and that you know you can do these things.
27
28 To protect your rights, we need to prevent others from denying you
29 these rights or asking you to surrender the rights. Therefore, you have
30 certain responsibilities if you distribute copies of the software, or if
31 you modify it: responsibilities to respect the freedom of others.
32
33 For example, if you distribute copies of such a program, whether
34 gratis or for a fee, you must pass on to the recipients the same
35 freedoms that you received. You must make sure that they, too, receive
36 or can get the source code. And you must show them these terms so they
37 know their rights.
38
39 Developers that use the GNU GPL protect your rights with two steps:
40 (1) assert copyright on the software, and (2) offer you this License
41 giving you legal permission to copy, distribute and/or modify it.
42
43 For the developers' and authors' protection, the GPL clearly explains
44 that there is no warranty for this free software. For both users' and
45 authors' sake, the GPL requires that modified versions be marked as
46 changed, so that their problems will not be attributed erroneously to
47 authors of previous versions.
48
49 Some devices are designed to deny users access to install or run
50 modified versions of the software inside them, although the manufacturer
51 can do so. This is fundamentally incompatible with the aim of
52 protecting users' freedom to change the software. The systematic
53 pattern of such abuse occurs in the area of products for individuals to
54 use, which is precisely where it is most unacceptable. Therefore, we
55 have designed this version of the GPL to prohibit the practice for those
56 products. If such problems arise substantially in other domains, we
57 stand ready to extend this provision to those domains in future versions
58 of the GPL, as needed to protect the freedom of users.
59
60 Finally, every program is threatened constantly by software patents.
61 States should not allow patents to restrict development and use of
62 software on general-purpose computers, but in those that do, we wish to
63 avoid the special danger that patents applied to a free program could
64 make it effectively proprietary. To prevent this, the GPL assures that
65 patents cannot be used to render the program non-free.
66
67 The precise terms and conditions for copying, distribution and
68 modification follow.
69
70 TERMS AND CONDITIONS
71
72 0. Definitions.
73
74 "This License" refers to version 3 of the GNU General Public License.
75
76 "Copyright" also means copyright-like laws that apply to other kinds of
77 works, such as semiconductor masks.
78
79 "The Program" refers to any copyrightable work licensed under this
80 License. Each licensee is addressed as "you". "Licensees" and
81 "recipients" may be individuals or organizations.
82
83 To "modify" a work means to copy from or adapt all or part of the work
84 in a fashion requiring copyright permission, other than the making of an
85 exact copy. The resulting work is called a "modified version" of the
86 earlier work or a work "based on" the earlier work.
87
88 A "covered work" means either the unmodified Program or a work based
89 on the Program.
90
91 To "propagate" a work means to do anything with it that, without
92 permission, would make you directly or secondarily liable for
93 infringement under applicable copyright law, except executing it on a
94 computer or modifying a private copy. Propagation includes copying,
95 distribution (with or without modification), making available to the
96 public, and in some countries other activities as well.
97
98 To "convey" a work means any kind of propagation that enables other
99 parties to make or receive copies. Mere interaction with a user through
100 a computer network, with no transfer of a copy, is not conveying.
101
102 An interactive user interface displays "Appropriate Legal Notices"
103 to the extent that it includes a convenient and prominently visible
104 feature that (1) displays an appropriate copyright notice, and (2)
105 tells the user that there is no warranty for the work (except to the
106 extent that warranties are provided), that licensees may convey the
107 work under this License, and how to view a copy of this License. If
108 the interface presents a list of user commands or options, such as a
109 menu, a prominent item in the list meets this criterion.
110
111 1. Source Code.
112
113 The "source code" for a work means the preferred form of the work
114 for making modifications to it. "Object code" means any non-source
115 form of a work.
116
117 A "Standard Interface" means an interface that either is an official
118 standard defined by a recognized standards body, or, in the case of
119 interfaces specified for a particular programming language, one that
120 is widely used among developers working in that language.
121
122 The "System Libraries" of an executable work include anything, other
123 than the work as a whole, that (a) is included in the normal form of
124 packaging a Major Component, but which is not part of that Major
125 Component, and (b) serves only to enable use of the work with that
126 Major Component, or to implement a Standard Interface for which an
127 implementation is available to the public in source code form. A
128 "Major Component", in this context, means a major essential component
129 (kernel, window system, and so on) of the specific operating system
130 (if any) on which the executable work runs, or a compiler used to
131 produce the work, or an object code interpreter used to run it.
132
133 The "Corresponding Source" for a work in object code form means all
134 the source code needed to generate, install, and (for an executable
135 work) run the object code and to modify the work, including scripts to
136 control those activities. However, it does not include the work's
137 System Libraries, or general-purpose tools or generally available free
138 programs which are used unmodified in performing those activities but
139 which are not part of the work. For example, Corresponding Source
140 includes interface definition files associated with source files for
141 the work, and the source code for shared libraries and dynamically
142 linked subprograms that the work is specifically designed to require,
143 such as by intimate data communication or control flow between those
144 subprograms and other parts of the work.
145
146 The Corresponding Source need not include anything that users
147 can regenerate automatically from other parts of the Corresponding
148 Source.
149
150 The Corresponding Source for a work in source code form is that
151 same work.
152
153 2. Basic Permissions.
154
155 All rights granted under this License are granted for the term of
156 copyright on the Program, and are irrevocable provided the stated
157 conditions are met. This License explicitly affirms your unlimited
158 permission to run the unmodified Program. The output from running a
159 covered work is covered by this License only if the output, given its
160 content, constitutes a covered work. This License acknowledges your
161 rights of fair use or other equivalent, as provided by copyright law.
162
163 You may make, run and propagate covered works that you do not
164 convey, without conditions so long as your license otherwise remains
165 in force. You may convey covered works to others for the sole purpose
166 of having them make modifications exclusively for you, or provide you
167 with facilities for running those works, provided that you comply with
168 the terms of this License in conveying all material for which you do
169 not control copyright. Those thus making or running the covered works
170 for you must do so exclusively on your behalf, under your direction
171 and control, on terms that prohibit them from making any copies of
172 your copyrighted material outside their relationship with you.
173
174 Conveying under any other circumstances is permitted solely under
175 the conditions stated below. Sublicensing is not allowed; section 10
176 makes it unnecessary.
177
178 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
179
180 No covered work shall be deemed part of an effective technological
181 measure under any applicable law fulfilling obligations under article
182 11 of the WIPO copyright treaty adopted on 20 December 1996, or
183 similar laws prohibiting or restricting circumvention of such
184 measures.
185
186 When you convey a covered work, you waive any legal power to forbid
187 circumvention of technological measures to the extent such circumvention
188 is effected by exercising rights under this License with respect to
189 the covered work, and you disclaim any intention to limit operation or
190 modification of the work as a means of enforcing, against the work's
191 users, your or third parties' legal rights to forbid circumvention of
192 technological measures.
193
194 4. Conveying Verbatim Copies.
195
196 You may convey verbatim copies of the Program's source code as you
197 receive it, in any medium, provided that you conspicuously and
198 appropriately publish on each copy an appropriate copyright notice;
199 keep intact all notices stating that this License and any
200 non-permissive terms added in accord with section 7 apply to the code;
201 keep intact all notices of the absence of any warranty; and give all
202 recipients a copy of this License along with the Program.
203
204 You may charge any price or no price for each copy that you convey,
205 and you may offer support or warranty protection for a fee.
206
207 5. Conveying Modified Source Versions.
208
209 You may convey a work based on the Program, or the modifications to
210 produce it from the Program, in the form of source code under the
211 terms of section 4, provided that you also meet all of these conditions:
212
213 a) The work must carry prominent notices stating that you modified
214 it, and giving a relevant date.
215
216 b) The work must carry prominent notices stating that it is
217 released under this License and any conditions added under section
218 7. This requirement modifies the requirement in section 4 to
219 "keep intact all notices".
220
221 c) You must license the entire work, as a whole, under this
222 License to anyone who comes into possession of a copy. This
223 License will therefore apply, along with any applicable section 7
224 additional terms, to the whole of the work, and all its parts,
225 regardless of how they are packaged. This License gives no
226 permission to license the work in any other way, but it does not
227 invalidate such permission if you have separately received it.
228
229 d) If the work has interactive user interfaces, each must display
230 Appropriate Legal Notices; however, if the Program has interactive
231 interfaces that do not display Appropriate Legal Notices, your
232 work need not make them do so.
233
234 A compilation of a covered work with other separate and independent
235 works, which are not by their nature extensions of the covered work,
236 and which are not combined with it such as to form a larger program,
237 in or on a volume of a storage or distribution medium, is called an
238 "aggregate" if the compilation and its resulting copyright are not
239 used to limit the access or legal rights of the compilation's users
240 beyond what the individual works permit. Inclusion of a covered work
241 in an aggregate does not cause this License to apply to the other
242 parts of the aggregate.
243
244 6. Conveying Non-Source Forms.
245
246 You may convey a covered work in object code form under the terms
247 of sections 4 and 5, provided that you also convey the
248 machine-readable Corresponding Source under the terms of this License,
249 in one of these ways:
250
251 a) Convey the object code in, or embodied in, a physical product
252 (including a physical distribution medium), accompanied by the
253 Corresponding Source fixed on a durable physical medium
254 customarily used for software interchange.
255
256 b) Convey the object code in, or embodied in, a physical product
257 (including a physical distribution medium), accompanied by a
258 written offer, valid for at least three years and valid for as
259 long as you offer spare parts or customer support for that product
260 model, to give anyone who possesses the object code either (1) a
261 copy of the Corresponding Source for all the software in the
262 product that is covered by this License, on a durable physical
263 medium customarily used for software interchange, for a price no
264 more than your reasonable cost of physically performing this
265 conveying of source, or (2) access to copy the
266 Corresponding Source from a network server at no charge.
267
268 c) Convey individual copies of the object code with a copy of the
269 written offer to provide the Corresponding Source. This
270 alternative is allowed only occasionally and noncommercially, and
271 only if you received the object code with such an offer, in accord
272 with subsection 6b.
273
274 d) Convey the object code by offering access from a designated
275 place (gratis or for a charge), and offer equivalent access to the
276 Corresponding Source in the same way through the same place at no
277 further charge. You need not require recipients to copy the
278 Corresponding Source along with the object code. If the place to
279 copy the object code is a network server, the Corresponding Source
280 may be on a different server (operated by you or a third party)
281 that supports equivalent copying facilities, provided you maintain
282 clear directions next to the object code saying where to find the
283 Corresponding Source. Regardless of what server hosts the
284 Corresponding Source, you remain obligated to ensure that it is
285 available for as long as needed to satisfy these requirements.
286
287 e) Convey the object code using peer-to-peer transmission, provided
288 you inform other peers where the object code and Corresponding
289 Source of the work are being offered to the general public at no
290 charge under subsection 6d.
291
292 A separable portion of the object code, whose source code is excluded
293 from the Corresponding Source as a System Library, need not be
294 included in conveying the object code work.
295
296 A "User Product" is either (1) a "consumer product", which means any
297 tangible personal property which is normally used for personal, family,
298 or household purposes, or (2) anything designed or sold for incorporation
299 into a dwelling. In determining whether a product is a consumer product,
300 doubtful cases shall be resolved in favor of coverage. For a particular
301 product received by a particular user, "normally used" refers to a
302 typical or common use of that class of product, regardless of the status
303 of the particular user or of the way in which the particular user
304 actually uses, or expects or is expected to use, the product. A product
305 is a consumer product regardless of whether the product has substantial
306 commercial, industrial or non-consumer uses, unless such uses represent
307 the only significant mode of use of the product.
308
309 "Installation Information" for a User Product means any methods,
310 procedures, authorization keys, or other information required to install
311 and execute modified versions of a covered work in that User Product from
312 a modified version of its Corresponding Source. The information must
313 suffice to ensure that the continued functioning of the modified object
314 code is in no case prevented or interfered with solely because
315 modification has been made.
316
317 If you convey an object code work under this section in, or with, or
318 specifically for use in, a User Product, and the conveying occurs as
319 part of a transaction in which the right of possession and use of the
320 User Product is transferred to the recipient in perpetuity or for a
321 fixed term (regardless of how the transaction is characterized), the
322 Corresponding Source conveyed under this section must be accompanied
323 by the Installation Information. But this requirement does not apply
324 if neither you nor any third party retains the ability to install
325 modified object code on the User Product (for example, the work has
326 been installed in ROM).
327
328 The requirement to provide Installation Information does not include a
329 requirement to continue to provide support service, warranty, or updates
330 for a work that has been modified or installed by the recipient, or for
331 the User Product in which it has been modified or installed. Access to a
332 network may be denied when the modification itself materially and
333 adversely affects the operation of the network or violates the rules and
334 protocols for communication across the network.
335
336 Corresponding Source conveyed, and Installation Information provided,
337 in accord with this section must be in a format that is publicly
338 documented (and with an implementation available to the public in
339 source code form), and must require no special password or key for
340 unpacking, reading or copying.
341
342 7. Additional Terms.
343
344 "Additional permissions" are terms that supplement the terms of this
345 License by making exceptions from one or more of its conditions.
346 Additional permissions that are applicable to the entire Program shall
347 be treated as though they were included in this License, to the extent
348 that they are valid under applicable law. If additional permissions
349 apply only to part of the Program, that part may be used separately
350 under those permissions, but the entire Program remains governed by
351 this License without regard to the additional permissions.
352
353 When you convey a copy of a covered work, you may at your option
354 remove any additional permissions from that copy, or from any part of
355 it. (Additional permissions may be written to require their own
356 removal in certain cases when you modify the work.) You may place
357 additional permissions on material, added by you to a covered work,
358 for which you have or can give appropriate copyright permission.
359
360 Notwithstanding any other provision of this License, for material you
361 add to a covered work, you may (if authorized by the copyright holders of
362 that material) supplement the terms of this License with terms:
363
364 a) Disclaiming warranty or limiting liability differently from the
365 terms of sections 15 and 16 of this License; or
366
367 b) Requiring preservation of specified reasonable legal notices or
368 author attributions in that material or in the Appropriate Legal
369 Notices displayed by works containing it; or
370
371 c) Prohibiting misrepresentation of the origin of that material, or
372 requiring that modified versions of such material be marked in
373 reasonable ways as different from the original version; or
374
375 d) Limiting the use for publicity purposes of names of licensors or
376 authors of the material; or
377
378 e) Declining to grant rights under trademark law for use of some
379 trade names, trademarks, or service marks; or
380
381 f) Requiring indemnification of licensors and authors of that
382 material by anyone who conveys the material (or modified versions of
383 it) with contractual assumptions of liability to the recipient, for
384 any liability that these contractual assumptions directly impose on
385 those licensors and authors.
386
387 All other non-permissive additional terms are considered "further
388 restrictions" within the meaning of section 10. If the Program as you
389 received it, or any part of it, contains a notice stating that it is
390 governed by this License along with a term that is a further
391 restriction, you may remove that term. If a license document contains
392 a further restriction but permits relicensing or conveying under this
393 License, you may add to a covered work material governed by the terms
394 of that license document, provided that the further restriction does
395 not survive such relicensing or conveying.
396
397 If you add terms to a covered work in accord with this section, you
398 must place, in the relevant source files, a statement of the
399 additional terms that apply to those files, or a notice indicating
400 where to find the applicable terms.
401
402 Additional terms, permissive or non-permissive, may be stated in the
403 form of a separately written license, or stated as exceptions;
404 the above requirements apply either way.
405
406 8. Termination.
407
408 You may not propagate or modify a covered work except as expressly
409 provided under this License. Any attempt otherwise to propagate or
410 modify it is void, and will automatically terminate your rights under
411 this License (including any patent licenses granted under the third
412 paragraph of section 11).
413
414 However, if you cease all violation of this License, then your
415 license from a particular copyright holder is reinstated (a)
416 provisionally, unless and until the copyright holder explicitly and
417 finally terminates your license, and (b) permanently, if the copyright
418 holder fails to notify you of the violation by some reasonable means
419 prior to 60 days after the cessation.
420
421 Moreover, your license from a particular copyright holder is
422 reinstated permanently if the copyright holder notifies you of the
423 violation by some reasonable means, this is the first time you have
424 received notice of violation of this License (for any work) from that
425 copyright holder, and you cure the violation prior to 30 days after
426 your receipt of the notice.
427
428 Termination of your rights under this section does not terminate the
429 licenses of parties who have received copies or rights from you under
430 this License. If your rights have been terminated and not permanently
431 reinstated, you do not qualify to receive new licenses for the same
432 material under section 10.
433
434 9. Acceptance Not Required for Having Copies.
435
436 You are not required to accept this License in order to receive or
437 run a copy of the Program. Ancillary propagation of a covered work
438 occurring solely as a consequence of using peer-to-peer transmission
439 to receive a copy likewise does not require acceptance. However,
440 nothing other than this License grants you permission to propagate or
441 modify any covered work. These actions infringe copyright if you do
442 not accept this License. Therefore, by modifying or propagating a
443 covered work, you indicate your acceptance of this License to do so.
444
445 10. Automatic Licensing of Downstream Recipients.
446
447 Each time you convey a covered work, the recipient automatically
448 receives a license from the original licensors, to run, modify and
449 propagate that work, subject to this License. You are not responsible
450 for enforcing compliance by third parties with this License.
451
452 An "entity transaction" is a transaction transferring control of an
453 organization, or substantially all assets of one, or subdividing an
454 organization, or merging organizations. If propagation of a covered
455 work results from an entity transaction, each party to that
456 transaction who receives a copy of the work also receives whatever
457 licenses to the work the party's predecessor in interest had or could
458 give under the previous paragraph, plus a right to possession of the
459 Corresponding Source of the work from the predecessor in interest, if
460 the predecessor has it or can get it with reasonable efforts.
461
462 You may not impose any further restrictions on the exercise of the
463 rights granted or affirmed under this License. For example, you may
464 not impose a license fee, royalty, or other charge for exercise of
465 rights granted under this License, and you may not initiate litigation
466 (including a cross-claim or counterclaim in a lawsuit) alleging that
467 any patent claim is infringed by making, using, selling, offering for
468 sale, or importing the Program or any portion of it.
469
470 11. Patents.
471
472 A "contributor" is a copyright holder who authorizes use under this
473 License of the Program or a work on which the Program is based. The
474 work thus licensed is called the contributor's "contributor version".
475
476 A contributor's "essential patent claims" are all patent claims
477 owned or controlled by the contributor, whether already acquired or
478 hereafter acquired, that would be infringed by some manner, permitted
479 by this License, of making, using, or selling its contributor version,
480 but do not include claims that would be infringed only as a
481 consequence of further modification of the contributor version. For
482 purposes of this definition, "control" includes the right to grant
483 patent sublicenses in a manner consistent with the requirements of
484 this License.
485
486 Each contributor grants you a non-exclusive, worldwide, royalty-free
487 patent license under the contributor's essential patent claims, to
488 make, use, sell, offer for sale, import and otherwise run, modify and
489 propagate the contents of its contributor version.
490
491 In the following three paragraphs, a "patent license" is any express
492 agreement or commitment, however denominated, not to enforce a patent
493 (such as an express permission to practice a patent or covenant not to
494 sue for patent infringement). To "grant" such a patent license to a
495 party means to make such an agreement or commitment not to enforce a
496 patent against the party.
497
498 If you convey a covered work, knowingly relying on a patent license,
499 and the Corresponding Source of the work is not available for anyone
500 to copy, free of charge and under the terms of this License, through a
501 publicly available network server or other readily accessible means,
502 then you must either (1) cause the Corresponding Source to be so
503 available, or (2) arrange to deprive yourself of the benefit of the
504 patent license for this particular work, or (3) arrange, in a manner
505 consistent with the requirements of this License, to extend the patent
506 license to downstream recipients. "Knowingly relying" means you have
507 actual knowledge that, but for the patent license, your conveying the
508 covered work in a country, or your recipient's use of the covered work
509 in a country, would infringe one or more identifiable patents in that
510 country that you have reason to believe are valid.
511
512 If, pursuant to or in connection with a single transaction or
513 arrangement, you convey, or propagate by procuring conveyance of, a
514 covered work, and grant a patent license to some of the parties
515 receiving the covered work authorizing them to use, propagate, modify
516 or convey a specific copy of the covered work, then the patent license
517 you grant is automatically extended to all recipients of the covered
518 work and works based on it.
519
520 A patent license is "discriminatory" if it does not include within
521 the scope of its coverage, prohibits the exercise of, or is
522 conditioned on the non-exercise of one or more of the rights that are
523 specifically granted under this License. You may not convey a covered
524 work if you are a party to an arrangement with a third party that is
525 in the business of distributing software, under which you make payment
526 to the third party based on the extent of your activity of conveying
527 the work, and under which the third party grants, to any of the
528 parties who would receive the covered work from you, a discriminatory
529 patent license (a) in connection with copies of the covered work
530 conveyed by you (or copies made from those copies), or (b) primarily
531 for and in connection with specific products or compilations that
532 contain the covered work, unless you entered into that arrangement,
533 or that patent license was granted, prior to 28 March 2007.
534
535 Nothing in this License shall be construed as excluding or limiting
536 any implied license or other defenses to infringement that may
537 otherwise be available to you under applicable patent law.
538
539 12. No Surrender of Others' Freedom.
540
541 If conditions are imposed on you (whether by court order, agreement or
542 otherwise) that contradict the conditions of this License, they do not
543 excuse you from the conditions of this License. If you cannot convey a
544 covered work so as to satisfy simultaneously your obligations under this
545 License and any other pertinent obligations, then as a consequence you may
546 not convey it at all. For example, if you agree to terms that obligate you
547 to collect a royalty for further conveying from those to whom you convey
548 the Program, the only way you could satisfy both those terms and this
549 License would be to refrain entirely from conveying the Program.
550
551 13. Use with the GNU Affero General Public License.
552
553 Notwithstanding any other provision of this License, you have
554 permission to link or combine any covered work with a work licensed
555 under version 3 of the GNU Affero General Public License into a single
556 combined work, and to convey the resulting work. The terms of this
557 License will continue to apply to the part which is the covered work,
558 but the special requirements of the GNU Affero General Public License,
559 section 13, concerning interaction through a network will apply to the
560 combination as such.
561
562 14. Revised Versions of this License.
563
564 The Free Software Foundation may publish revised and/or new versions of
565 the GNU General Public License from time to time. Such new versions will
566 be similar in spirit to the present version, but may differ in detail to
567 address new problems or concerns.
568
569 Each version is given a distinguishing version number. If the
570 Program specifies that a certain numbered version of the GNU General
571 Public License "or any later version" applies to it, you have the
572 option of following the terms and conditions either of that numbered
573 version or of any later version published by the Free Software
574 Foundation. If the Program does not specify a version number of the
575 GNU General Public License, you may choose any version ever published
576 by the Free Software Foundation.
577
578 If the Program specifies that a proxy can decide which future
579 versions of the GNU General Public License can be used, that proxy's
580 public statement of acceptance of a version permanently authorizes you
581 to choose that version for the Program.
582
583 Later license versions may give you additional or different
584 permissions. However, no additional obligations are imposed on any
585 author or copyright holder as a result of your choosing to follow a
586 later version.
587
588 15. Disclaimer of Warranty.
589
590 THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
591 APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
592 HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
593 OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
594 THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
595 PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
596 IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
597 ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
598
599 16. Limitation of Liability.
600
601 IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
602 WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
603 THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
604 GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
605 USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
606 DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
607 PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
608 EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
609 SUCH DAMAGES.
610
611 17. Interpretation of Sections 15 and 16.
612
613 If the disclaimer of warranty and limitation of liability provided
614 above cannot be given local legal effect according to their terms,
615 reviewing courts shall apply local law that most closely approximates
616 an absolute waiver of all civil liability in connection with the
617 Program, unless a warranty or assumption of liability accompanies a
618 copy of the Program in return for a fee.
619
620 END OF TERMS AND CONDITIONS
621
622 How to Apply These Terms to Your New Programs
623
624 If you develop a new program, and you want it to be of the greatest
625 possible use to the public, the best way to achieve this is to make it
626 free software which everyone can redistribute and change under these terms.
627
628 To do so, attach the following notices to the program. It is safest
629 to attach them to the start of each source file to most effectively
630 state the exclusion of warranty; and each file should have at least
631 the "copyright" line and a pointer to where the full notice is found.
632
633 <one line to give the program's name and a brief idea of what it does.>
634 Copyright (C) <year> <name of author>
635
636 This program is free software: you can redistribute it and/or modify
637 it under the terms of the GNU General Public License as published by
638 the Free Software Foundation, either version 3 of the License, or
639 (at your option) any later version.
640
641 This program is distributed in the hope that it will be useful,
642 but WITHOUT ANY WARRANTY; without even the implied warranty of
643 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
644 GNU General Public License for more details.
645
646 You should have received a copy of the GNU General Public License
647 along with this program. If not, see <http://www.gnu.org/licenses/>.
648
649 Also add information on how to contact you by electronic and paper mail.
650
651 If the program does terminal interaction, make it output a short
652 notice like this when it starts in an interactive mode:
653
654 <program> Copyright (C) <year> <name of author>
655 This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
656 This is free software, and you are welcome to redistribute it
657 under certain conditions; type `show c' for details.
658
659 The hypothetical commands `show w' and `show c' should show the appropriate
660 parts of the General Public License. Of course, your program's commands
661 might be different; for a GUI interface, you would use an "about box".
662
663 You should also get your employer (if you work as a programmer) or school,
664 if any, to sign a "copyright disclaimer" for the program, if necessary.
665 For more information on this, and how to apply and follow the GNU GPL, see
666 <http://www.gnu.org/licenses/>.
667
668 The GNU General Public License does not permit incorporating your program
669 into proprietary programs. If your program is a subroutine library, you
670 may consider it more useful to permit linking proprietary applications with
671 the library. If this is what you want to do, use the GNU Lesser General
672 Public License instead of this License. But first, please read
673 <http://www.gnu.org/philosophy/why-not-lgpl.html>.
0 Credits go to
1
2 Joshua M. Clulow for his terminal-based presentation tool in node.js
3 https://github.com/jclulow/vtmc
4
5 David Parsons for his inspiring Markdown implementation in C
6 https://github.com/Orc/discount
7
0 #
1 # Makefile
2 # Copyright (C) 2015 Michael Goehler
3 #
4 # This file is part of mdp.
5 #
6 # This program is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation, either version 3 of the License, or
9 # (at your option) any later version.
10 #
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
18 #
19
20 UNAME_S := $(shell uname -s 2>/dev/null || echo not)
21
22 SOURCES = $(wildcard src/*.c)
23 OBJECTS = $(SOURCES:.c=.o)
24 TARGET = mdp
25 DESTDIR =
26 PREFIX = /usr/local
27
28 CURSES = ncursesw
29 LDFLAGS ?= -s
30
31 ifeq (Windows_NT,$(OS))
32 ifeq (,$(findstring CYGWIN,$(UNAME_S)))
33 CURSES := pdcurses
34 endif
35 endif
36
37 ifeq ($(UNAME_S),Darwin)
38 CURSES := ncurses
39 LDFLAGS :=
40 endif
41
42 ifeq ($(DEBUG),1)
43 LDFLAGS :=
44 endif
45
46 LDLIBS = -l$(CURSES)
47
48 all: $(TARGET)
49
50 $(TARGET): src
51 $(CC) $(OBJECTS) $(LDLIBS) $(LDFLAGS) -o $(TARGET)
52
53 src:
54 $(MAKE) $(MFLAGS) -C src
55
56 clean:
57 $(MAKE) -C src clean
58 $(RM) $(TARGET)
59
60 install:
61 install -d $(DESTDIR)$(PREFIX)/bin
62 install -m 755 $(TARGET) $(DESTDIR)$(PREFIX)/bin/$(TARGET)
63 install -d $(DESTDIR)$(PREFIX)/share/man/man1
64 install -m 644 mdp.1 $(DESTDIR)$(PREFIX)/share/man/man1/$(TARGET).1
65
66 uninstall:
67 $(RM) $(DESTDIR)$(PREFIX)/$(TARGET)
68
69 .PHONY: all clean install src uninstall
0
1 ## mdp - A command-line based markdown presentation tool.
2
3 ![image](https://cloud.githubusercontent.com/assets/2237222/5810237/797c494c-a043-11e4-9dbd-959cab4055fa.gif)
4
5 ---
6
7 ***How to get started:***
8
9 mdp needs the ncursesw headers to compile.
10 So make sure you have them installed:
11 - on Ubuntu/Debian you need `libncursesw5` and `libncursesw5-dev`
12 - on Cygwin you need `libncursesw10` and `libncurses-devel`
13
14 Now download and install mdp:
15
16 $ git clone https://github.com/visit1985/mdp.git
17 $ cd mdp
18 $ make
19 $ make install
20 $ mdp sample.md
21
22 - On Arch, you can use the existing [AUR package](https://aur.archlinux.org/packages/mdp-git/).
23 - On Slackware, grab the SlackBuild here: (http://slackbuilds.org/apps/mdp/), or run `sbopkg -i mdp`.
24 - On FreeBSD, you can use the port [misc/mdp](http://www.freshports.org/misc/mdp).
25 - On OS-X, use the existing [Homebrew Formula](http://brewformulas.org/Mdp) by running `brew install mdp`.
26
27 Most terminals support 256 colors only if the TERM variable is
28 set correctly. To enjoy mdp's color fading feature:
29
30 $ export TERM=xterm-256color
31
32 ---
33
34 ***How to use it:***
35
36 Horizontal rulers are used as slide separator.
37
38 Supports basic markdown formating:
39
40 - line wide markup
41 - headlines
42 - code
43 - quotes
44 - unordered list
45
46 - in-line markup
47 - bold text
48 - underlined text
49 - code
50
51 Supports headers prefixed by @ symbol.
52
53 - first two header lines are displayed as title and author
54 in top and bottom bar
55
56 Review sample.md for more details.
57
58 ---
59
60 ***Controls:***
61
62 - h, j, k, l, Arrow keys,
63 Space, Enter, Backspace,
64 Page Up, Page Down - next/previous slide
65 - Home, g - go to first slide
66 - End, G - go to last slide
67 - 1-9 - go to slide n
68 - r - reload input file
69 - q - exit
70
71
72 ---
73
74 ***How to debug it:***
75
76 To make a debug version of `mdp`, just type:
77
78 $ make DEBUG=1
79
0 #if !defined( BITOPS_H )
1 #define BITOPS_H
2
3 /*
4 * Macros to do bit operations on integer variables.
5 * Copyright (C) 2015 Michael Goehler
6 *
7 * This file is part of mdp.
8 *
9 * This program is free software: you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation, either version 3 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program. If not, see <http://www.gnu.org/licenses/>.
21 *
22 *
23 * macro: SET_BIT to set bit at pos of var to 1
24 * macro: CLEAR_BIT to set bit at pos of var to 0
25 * macro: TOGGLE_BIT to toggle bit at pos of var from 1 to 0 and vice versa
26 * macro: CHECK_BIT returns > 0 if bit at pos of var is set to 1
27 *
28 * Example:
29 * int i = 0;
30 * i = SET_BIT(i, 2);
31 * if(CHECK_BIT(i, 2))
32 * printf("bit 2 is set\n");
33 * printf("value of i is %d\n", i);
34 *
35 */
36
37 #define SET_BIT(var, pos) ((var) |= (1<<(pos)))
38 #define CLEAR_BIT(var, pos) ((var) &= (~(1<<(pos))))
39 #define TOGGLE_BIT(var, pos) ((var) ^= (1<<(pos)))
40 #define CHECK_BIT(var, pos) ((var) & (1<<(pos)))
41
42 #endif // !defined( BITOPS_H )
0 #if !defined( COMMON_H )
1 #define COMMON_H
2
3 /*
4 * Common macros.
5 * Copyright (C) 2015 Michael Goehler
6 *
7 * This file is part of mdp.
8 *
9 * This program is free software: you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation, either version 3 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program. If not, see <http://www.gnu.org/licenses/>.
21 *
22 *
23 * type: bool variable stores only true or false.
24 *
25 * macro: MAX returns the higher one of two input variables
26 * macro: MIN returns the lower one of two input variables
27 *
28 */
29
30 #if defined( __STDC__ ) // for standard C compiler
31 #if __STDC_VERSION__ >= 199901L // for C99 and later
32 #include <stdbool.h>
33 #else // __STDC_VERSION__ >= 199901L
34 #if !defined( bool )
35 typedef enum {
36 false = 0,
37 true = 1
38 } bool;
39 #endif // !defined( bool )
40 #endif // __STDC_VERSION__ >= 199901L
41 #else // defined( __STDC__ )
42 #define bool int
43 #define true 1
44 #define false 0
45 #endif // defined( __STDC__ )
46
47 #define MAX(a, b) ({ typeof(a) _a = a; typeof(b) _b = b; _a > _b? _a : _b; })
48 #define MIN(a, b) ({ typeof(a) _a = a; typeof(b) _b = b; _a < _b? _a : _b; })
49
50 #endif // !defined( COMMON_H )
0 #if !defined( CSTACK_H )
1 #define CSTACK_H
2
3 /*
4 * An implementation of a char stack in heap memory.
5 * Copyright (C) 2015 Michael Goehler
6 *
7 * This file is part of mdp.
8 *
9 * This program is free software: you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation, either version 3 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program. If not, see <http://www.gnu.org/licenses/>.
21 *
22 *
23 * struct: cstack_t which defines char stack type in heap memory
24 *
25 * function: cstack_init to intialize struct of type cstack_t
26 * function: cstack_t->push to add one char on top if the stack
27 * function: cstack_t->pop to remove the top char from the stack
28 * function: cstack_t->top to test if the top char is a given char
29 * function: cstack_t->empty to test if the stack is empty
30 * function: cstack_t->delete to free the allocated memory
31 *
32 * Example:
33 * cstack_t *p = cstack_init();
34 * (p->push)(p, 'X');
35 * printf("%c\n", (p->pop)(p));
36 * (p->delete)(p);
37 *
38 */
39
40 #include "common.h"
41
42 typedef struct _cstack_t {
43 wchar_t *content;
44 size_t alloc;
45 size_t size;
46 int head;
47 void (*push)(struct _cstack_t *self, wchar_t c);
48 wchar_t (*pop)(struct _cstack_t *self);
49 bool (*top)(struct _cstack_t *self, wchar_t c);
50 bool (*empty)(struct _cstack_t *self);
51 void (*delete)(struct _cstack_t *self);
52 } cstack_t;
53
54 cstack_t *cstack_init();
55 void cstack_push(cstack_t *self, wchar_t c);
56 wchar_t cstack_pop(cstack_t *self);
57 bool cstack_top(cstack_t *self, wchar_t c);
58 bool cstack_empty(cstack_t *self);
59 void cstack_delete(cstack_t *self);
60
61 #endif // !defined( CSTACK_H )
0 #if !defined( CSTRING_H )
1 #define CSTRING_H
2
3 /*
4 * An implementation of expandable c strings in heap memory.
5 * Copyright (C) 2015 Michael Goehler
6 *
7 * This file is part of mdp.
8 *
9 * This program is free software: you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation, either version 3 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program. If not, see <http://www.gnu.org/licenses/>.
21 *
22 *
23 * struct: cstring_t which defines a expandable c string type in heap memory
24 *
25 * function: cstring_init to intialize struct of type cstring_t
26 * function: cstring_t->expand to add one character to the struct
27 * function: cstring_t->expand_arr to add a string to the struct
28 * function: cstring_t->strip to remove a substring
29 * function: cstring_t->reset to clear and reuse the struct
30 * function: cstring_t->delete to free the allocated memory
31 *
32 * Example:
33 * cstring_t *p = cstring_init();
34 * (p->expand)(p, 'X');
35 * (p->delete)(p);
36 *
37 */
38
39 // The amount of memory allocated from heap when string expansion hits the
40 // allocated memory limit
41 #define REALLOC_ADD 10
42
43 typedef struct _cstring_t {
44 wchar_t *value;
45 size_t size;
46 size_t alloc;
47 void (*expand)(struct _cstring_t *self, wchar_t x);
48 void (*expand_arr)(struct _cstring_t *self, wchar_t *x);
49 void (*strip)(struct _cstring_t *self, int pos, int len);
50 void (*reset)(struct _cstring_t *self);
51 void (*delete)(struct _cstring_t *self);
52 } cstring_t;
53
54 cstring_t *cstring_init();
55 void cstring_expand(cstring_t *self, wchar_t x);
56 void cstring_expand_arr(cstring_t *self, wchar_t *x);
57 void cstring_strip(cstring_t *self, int pos, int len);
58 void cstring_reset(cstring_t *self);
59 void cstring_delete(cstring_t *self);
60
61 #endif // !defined( CSTRING_H )
0 #if !defined( MAIN_H )
1 #define MAIN_H
2
3 /*
4 * mdp -- A command-line based markdown presentation tool.
5 * Copyright (C) 2015 Michael Goehler
6 *
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 *
20 */
21
22 #include "parser.h"
23 #include "viewer.h"
24
25 #define MDP_VER_MAJOR 1
26 #define MDP_VER_MINOR 0
27 #define MDP_VER_REVISION 3
28
29 #endif // !defined( MAIN_H )
0 #if !defined( MARKDOWN_H )
1 #define MARKDOWN_H
2
3 /*
4 * An implementation of markdown objects.
5 * Copyright (C) 2015 Michael Goehler
6 *
7 * This file is part of mdp.
8 *
9 * This program is free software: you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation, either version 3 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program. If not, see <http://www.gnu.org/licenses/>.
21 *
22 *
23 * enum: line_bitmask which enumerates markdown formating bits
24 *
25 * struct: deck_t the root object representing a deck of slides
26 * struct: slide_t a linked list element of type slide contained in a deck
27 * struct: line_t a linked list element of type line contained in a slide
28 *
29 * function: new_deck to initialize a new deck
30 * function: new_slide to initialize a new linked list of type slide
31 * function: next_slide to extend a linked list of type slide by one element
32 * function: new_line to initialize a new linked list of type line
33 * function: next_line to extend a linked list of type line by one element
34 * function: free_line to free a line elements memory
35 * function: free_deck to free a deck's memory
36 *
37 */
38
39 #include "cstring.h"
40 #include "bitops.h"
41
42 enum line_bitmask {
43 IS_H1,
44 IS_H1_ATX,
45 IS_H2,
46 IS_H2_ATX,
47 IS_QUOTE,
48 IS_CODE,
49 IS_TILDE_CODE,
50 IS_HR,
51 IS_UNORDERED_LIST_1,
52 IS_UNORDERED_LIST_2,
53 IS_UNORDERED_LIST_3,
54 IS_UNORDERED_LIST_EXT,
55 IS_CENTER,
56 IS_STOP,
57 IS_EMPTY
58 };
59
60 typedef struct _line_t {
61 cstring_t *text;
62 struct _line_t *prev;
63 struct _line_t *next;
64 int bits;
65 int length;
66 int offset;
67 } line_t;
68
69 typedef struct _slide_t {
70 line_t *line;
71 struct _slide_t *prev;
72 struct _slide_t *next;
73 int lines;
74 int stop;
75 } slide_t;
76
77 typedef struct _deck_t {
78 line_t *header;
79 slide_t *slide;
80 int slides;
81 int headers;
82 } deck_t;
83
84 line_t *new_line();
85 line_t *next_line(line_t *prev);
86 slide_t *new_slide();
87 slide_t *next_slide(slide_t *prev);
88 deck_t *new_deck();
89 void free_line(line_t *l);
90 void free_deck(deck_t *);
91
92 #endif // !defined( MARKDOWN_H )
0 #if !defined( PARSER_H )
1 #define PARSER_H
2
3 /*
4 * Functions necessary to parse a file and transform its content into
5 * a deck of slides containing lines. All based on markdown formating
6 * rules.
7 * Copyright (C) 2015 Michael Goehler
8 *
9 * This file is part of mdp.
10 *
11 * This program is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation, either version 3 of the License, or
14 * (at your option) any later version.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program. If not, see <http://www.gnu.org/licenses/>.
23 *
24 *
25 * function: markdown_load is the main function which reads a file handle,
26 * and initializes deck, slides and lines
27 * function: markdown_analyse which is used to identify line wide formating
28 * rules in given line
29 * function: markdown_debug to print a report of the generated data structure
30 * function: adjust_line_length to calculate line length excluding markup
31 * function: is_utf8 detects multi-byte char
32 * function: length_utf8 calculates the amount of bytes used for a multi-byte
33 * char
34 * function: next_nonblank, next_blank, next_word to calculate string offset's
35 *
36 */
37
38 #include "common.h"
39 #include "markdown.h"
40 #include "cstack.h"
41
42 #if defined( CYGWIN )
43 #undef WEOF
44 #define WEOF (0xffff)
45 #endif // defined( CYGWIN )
46
47 #define EXPAND_TABS 4
48 #define CODE_INDENT 4
49 #define UNORDERED_LIST_MAX_LEVEL 3
50
51 deck_t *markdown_load(FILE *input);
52 int markdown_analyse(cstring_t *text, int prev);
53 void markdown_debug(deck_t *deck, int debug);
54 void adjust_line_length(line_t *line);
55 int next_nonblank(cstring_t *text, int i);
56 int prev_blank(cstring_t *text, int i);
57 int next_blank(cstring_t *text, int i);
58 int next_word(cstring_t *text, int i);
59 int next_nontilde(cstring_t *text, int i);
60
61 #endif // !defined( PARSER_H )
0 #if !defined( URL_H )
1 #define URL_H
2
3 /*
4 * An object to store all urls of a slide.
5 * Copyright (C) 2015 Michael Goehler
6 *
7 * This file is part of mdp.
8 *
9 * This program is free software: you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation, either version 3 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program. If not, see <http://www.gnu.org/licenses/>.
21 *
22 * function: url_init to intialize a new url object
23 */
24
25 typedef struct _url_t {
26 wchar_t *link_name;
27 wchar_t *target;
28 int x;
29 int y;
30 struct _url_t *next;
31 } url_t;
32
33 void url_init(void);
34 int url_add(const wchar_t *link_name, int link_name_length, const wchar_t *target, int target_length, int x, int y);
35 wchar_t* url_get_target(int index);
36 wchar_t* url_get_name(int index);
37 int url_get_amount(void);
38 void url_purge(void);
39 void url_dump(void);
40 int url_count_inline(const wchar_t *line);
41 int url_len_inline(const wchar_t *value);
42
43 #endif // !defined( URL_H )
0 #if !defined( VIEWER_H )
1 #define VIEWER_H
2
3 /*
4 * Functions necessary to display a deck of slides in different color modes
5 * using ncurses. Only white, red, and blue are supported, as they can be
6 * faded in 256 color mode.
7 * Copyright (C) 2015 Michael Goehler
8 *
9 * This file is part of mdp.
10 *
11 * This program is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation, either version 3 of the License, or
14 * (at your option) any later version.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program. If not, see <http://www.gnu.org/licenses/>.
23 *
24 *
25 * function: ncurses_display initializes ncurses, defines colors, calculates
26 * window geometry and handles key strokes
27 * function: add_line detects inline markdown formating and prints line char
28 * by char
29 * function: fade_in, fade_out implementing color fading in 256 color mode
30 * function: int_length to calculate decimal length of slide count
31 *
32 */
33
34 #define _GNU_SOURCE // enable ncurses wchar support
35 #define _XOPEN_SOURCE_EXTENDED 1 // enable ncurses wchar support
36
37 #if defined( WIN32 )
38 #include <curses.h>
39 #else
40 #include <ncurses.h>
41 #endif
42
43 #include "common.h"
44 #include "parser.h"
45 #include "cstack.h"
46 #include "url.h"
47
48 #define CP_WHITE 1 // 255
49 #define CP_BLUE 2 // 123
50 #define CP_RED 3 // 213
51 #define CP_YELLOW 4 // 208
52 #define CP_BLACK 5 // CP_WHITE with foreground and background swapped
53
54 #define FADE_DELAY 15000 // micro seconds
55 #define GOTO_SLIDE_DELAY 5 // tenths of seconds
56
57 int ncurses_display(deck_t *deck, int notrans, int nofade, int invert, int reload, int noreload, int slidenum);
58 void add_line(WINDOW *window, int y, int x, line_t *line, int max_cols, int colors);
59 void inline_display(WINDOW *window, const wchar_t *c, const int colors);
60 void fade_out(WINDOW *window, int trans, int colors, int invert);
61 void fade_in(WINDOW *window, int trans, int colors, int invert);
62 int int_length (int val);
63 int get_slide_number(char init);
64
65 #endif // !defined( VIEWER_H )
0 %title: The Road Not Taken
1 %author: Robert Frost
2
3 Two roads diverged in a yellow wood, and sorry I could not travel both. And be one traveler, long I stood, and looked down one as far as I could. To where it bent in the undergrowth.
4
5 Then took the other, as just as fair, and having perhaps the better claim. Because it was grassy and wanted wear, though as for that the passing there Had worn them really about the same. And both that morning equally lay, in leaves no step had trodden black.
6
7 Oh, I kept the first for another day! Yet knowing how way leads on to way. I doubted if I should ever come back, I shall be telling this with a sigh. Somewhere ages and ages hence: Two roads diverged in a wood, and I. I took the one less traveled by, and that has made all the difference.
8
+143
-0
mdp.1 less more
0 .\" This is the groff documentation source for MDP
1 .\"
2 .\" Preview with: groff -man -Tascii mdp.1
3 .\" or: man -l mdp.1
4 .\"
5 .
6 .
7 .TH MDP 1 "2015-04-10" "User Commands"
8 .SH NAME
9 mdp \- A command-line based
10 markdown presentation tool
11 .SH SYNOPSIS
12 .B mdp
13 .RI [ OPTION ].\|.\|.\|
14 .RI [ FILE ]
15 .
16 .SH DESCRIPTION
17 .B mdp
18 is a command-line program that allows you to make elegant presentations from
19 .B markdown formatted
20 .IR FILE s.
21 .PP
22 It is as easy as write your presentation content in the text editor of your
23 preference and launch the presentation from the command-line.
24 .
25 .SH OPTIONS
26 .SS "Input Control"
27 .TP
28 .IR FILE
29 The input file from which the presentation is read. If no file is specified,
30 or if the file name is
31 .BR \- ","
32 the presentation is read from standard input.
33 .SS "Output Control"
34 .TP
35 .BR \-f ", " \-\^\-nofade
36 Disable color fading in 256 color mode.
37 .TP
38 .BR \-i ", " \-\^\-invert
39 Swap black and white color.
40 .TP
41 .BR \-t ", " \-\^\-notrans
42 Disable transparency in transparent terminal.
43 .
44 .SS "Miscellaneous Options"
45 .TP
46 .BR \-h ", " \-\^\-help
47 Display usage message and exit.
48 .TP
49 .BR \-d ", " \-\^\-debug
50 Enable debug messages on STDERR. Add multiple times to increases debug level.
51 .
52 .SH MARKDOWN FORMATTING
53 For a complete list of supported markups, refer the sample presentation
54 (sample.md) provided alongside
55 .BR mdp ,\|
56 or online available at
57 .IR https://github.com/visit1985/mdp .
58 .SS "Slides"
59 The input
60 .IR FILE
61 is split into multiple slides by horizontal rules. Each consisting of at least
62 3
63 .B \-\-\-
64 or
65 .B ***
66 characters on a single line.
67 .B This line must be prefixed by an completely empty line.
68 It can also contain spaces but no other characters.
69 .PP
70 If any slide is too large to fit into your current screen, an error message
71 will be displayed at the moment the presentation is launched.
72 .
73 .SS "Line-by-Line Mode"
74 .SS "Block-by-Block Mode"
75 A single
76 .BR "<br>" ", " "<BR>" " or " "^"
77 on an otherwise empty line signals
78 .B mdp
79 to stop output of the current slide (stop point) and wait for a key-press by
80 the user.
81 .PP
82 This enables the user to display bullet points or list items one by one
83 (line by line) or block by block.
84 .
85 .SS "Headers"
86 .B mdp
87 supports header lines in the format of
88 .BR @ "[DESCRIPTION] " [VALUE]
89 The first two header lines are displayed as title and author in top and
90 bottom bar.
91 .PP
92 Headers are only recognized at the top of the input
93 .IR FILE .
94 .
95 .SS "Line spanning markup"
96 Supported are headlines, code blocks, quotes and unordered lists.
97 .
98 .SS "In-line markup"
99 As well as bold text, underlined text and in-line code.
100 .
101 .SH COLOR SUPPORT
102 Most terminals are able to display 256 colors these days. But some of them
103 enable only 16 colors by default. To enjoy
104 .BR mdp "'s"
105 full capabilities, these terminals need to be signaled to enable 256 color
106 mode. This is usually done by setting the TERM environment variable.
107 .PP
108 .BR "export TERM=xterm-256color"
109 .
110 .SH KEYBOARD CONTROLS
111 .TP
112 .BR "h, j, k, l, Arrow keys, Space, Enter, Backspace, Page Up, Page Down"
113 Display next/previous slide or continue after a stop point.
114 .TP
115 .BR "g, Home"
116 Jump to first slide.
117 .TP
118 .BR "G, End"
119 Jump to last slide.
120 .TP
121 .BR "1..N"
122 Jump to
123 .BR N "th"
124 slide.
125 .TP
126 .BR "r"
127 Reload the input
128 .IR FILE .\|
129 This key is disabled if input was read from standard input.
130 .TP
131 .BR "q"
132 Exit
133 .BR mdp "."
134 .
135 .SH AUTHOR
136 Written by Michael Goehler and others, see
137 .IR https://github.com/visit1985/mdp/blob/master/AUTHORS "."
138 .SH COPYRIGHT
139 Copyright (C) 2015 Michael Goehler
140 .PP
141 This is free software; see the source for copying conditions. There is NO
142 warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
0 {
1 "settings":
2 {
3 "tab_size": 4,
4 "translate_tabs_to_spaces": true,
5 "use_tab_stops": false
6 }
7 ,"folders":
8 [
9 {
10 "follow_symlinks": true,
11 "path": ".",
12 "file_exclude_patterns": [".*", "mdp", "mdp.sublime-project", "mdp.sublime-workspace"]
13 }
14 ]
15 ,"build_systems":
16 [
17 {
18 "name": "mdp",
19 "env": {
20 "DEBUG": "1"
21 },
22 "cmd": ["make"],
23 "working_dir": "${project_path:${folder}}",
24
25 "variants":
26 [
27 {
28 "name": "Clean",
29 "cmd": ["make", "clean"]
30 }
31 ]
32 }
33 ]
34 }
0 %title: mdp - Sample Presentation
1 %author: visit1985
2 %date: 2014-09-22
3
4 -> mdp <-
5 =========
6
7 -> A command-line based markdown presentation tool. <-
8
9 _Basic controls:_
10
11 next slide *Enter*, *Space*, *Page Down*, *j*, *l*,
12 *Down Arrow*, *Right Arrow*
13
14 previous slide *Backspace*, *Page Up*, *h*, *k*,
15 *Up Arrow*, *Left Arrow*
16
17 quit *q*
18 reload *r*
19 slide N *1..9*
20 first slide *Home*, *g*
21 last slide *End*, *G*
22
23 -------------------------------------------------
24
25 -> # Supported markdown formatting <-
26
27 The input file is split into multiple slides by
28 horizontal rules (hr). A hr consisting of at
29 least 3 *\** or *-*. It can also contain spaces but
30 no other characters.
31
32 Each of these represents the start of a new slide.
33
34 \* \* \*
35 \---
36 \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*
37 \- - -
38
39 -------------------------------------------------
40
41 -> # Supported markdown formatting <-
42
43 First-level headers can be prefixed by single *#*
44 or underlined by *===*.
45
46 \# first-level
47
48 becomes
49
50 # first-level
51
52 -------------------------------------------------
53
54 -> # Supported markdown formatting <-
55
56 Second-level headers can be prefixed by *##* or
57 underlined by *---*.
58
59 second-level
60 \------------
61
62 becomes
63
64 second-level
65 ------------
66
67
68 -------------------------------------------------
69
70 -> # Supported markdown formatting's <-
71
72 Inline codes are surrounded with backticks.
73
74 C program starts with \`main()\`.
75
76 becomes
77
78 C program starts with `main()`.
79
80 -------------------------------------------------
81
82 -> # Supported markdown formatting <-
83
84 Code blocks are automatically detected by 4
85 spaces at the beginning of a line.
86
87 Tabs are automatically expanded to 4 spaces
88 while parsing the input.
89
90 \ int main(int argc, char \*argv[]) {
91 \ printf("%s\\n", "Hello world!");
92 \ }
93
94 becomes
95
96 int main(int argc, char *argv[]) {
97 printf("%s\n", "Hello world!");
98 }
99
100 -------------------------------------------------
101
102 -> # Supported markdown formatting <-
103
104 You can also use [pandoc](http://pandoc.org/demo/example9/pandocs-markdown.html)'s fenced code block extension.
105 Use at least three ~ chars to open and at least as many or
106 more ~ for closing.
107
108 \~~~ {.numberLines}
109 \int main(int argc, char \*argv[]) {
110 \ printf("%s\\n", "Hello world!");
111 \}
112 \~~~~~~~~~~~~~~~~~~
113
114 becomes
115
116 ~~~ {.numberLines}
117 int main(int argc, char \*argv[]) {
118 printf("%s\\n", "Hello world!");
119 }
120 ~~~~~~~~~~~~~~~~~~
121
122 Pandoc attributes (like ".numberlines" etc.) will be ignored
123
124 -------------------------------------------------
125
126 -> # Supported markdown formatting <-
127
128 Quotes are auto-detected by preceding *>*.
129
130 Multiple *>* are interpreted as nested quotes.
131
132 \> quote
133 \>> nested quote 1
134 \> > nested quote 2
135
136 becomes
137
138 > quote
139 >> nested quote 1
140 > > nested quote 2
141
142 -------------------------------------------------
143
144 -> # Supported markdown formatting <-
145
146 Inline highlighting is supported as followed:
147
148 \- *\** colors text as red
149 \- *\_* underlines text
150
151 \_some\_ \*highlighted\* \_\*text\*\_
152
153 becomes
154
155 _some_ *highlighted* _*text*_
156
157 -------------------------------------------------
158
159 -> # Supported markdown formatting <-
160
161 Backslashes force special markdown characters
162 like *\**, *\_*, *#* and *>* to be printed as normal
163 characters.
164
165 \\\*special\\\*
166
167 becomes
168
169 \*special\*
170
171 -------------------------------------------------
172
173 -> # Supported markdown formatting <-
174
175 Leading *\** or *-* indicate lists.
176
177 list
178 \* major
179 \ - minor
180 \ - \*important\*
181 \ detail
182 \ - minor
183
184 becomes
185
186 list
187 * major
188 - minor
189 - *important*
190 detail
191 - minor
192
193 -------------------------------------------------
194
195 -> # Supported markdown formatting <-
196
197 A single *\<br\>* or *^* in a line indicates mdp
198 to stop the output on that position.
199
200 This can be used to show bullet points
201 line by line.
202
203 *\<br\>* is also not displayed in HTML converted
204 output.
205
206 Agenda
207 <br>
208 * major
209 <br>
210 * minor
211 <br>
212 * major
213 ^
214 * minor
215 ^
216 * detail
217
218 -------------------------------------------------
219
220 -> # Supported markdown formatting <-
221
222 Leading *->* indicates centering.
223
224 \-> # test <-
225 \-> ## test <-
226 \-> test
227 \-> \_\*test\*\_ <-
228
229 becomes
230
231 -> # test <-
232 -> ## test <-
233 -> test
234 -> _*test*_ <-
235
236 -------------------------------------------------
237
238 -> # Supported markdown formatting <-
239
240 URL in pandoc style are supported:
241
242 \[Google](http://www.google.com/)
243
244 becomes
245
246 [Google](http://www.google.com/)
247
248 -------------------------------------------------
249
250 -> ## More information about markdown <-
251
252 can be found in the [markdown documentation](http://daringfireball.net/projects/markdown/).
253
254 -------------------------------------------------
255
256 -> # Support for UTF-8 special characters <-
257
258 Here are some examples.
259
260 ae = ä, oe = ö, ue = ü, ss = ß
261 upsilon = Ʊ, phi = ɸ
262
263 ▛▀▀▀▀▀▀▀▀▀▜
264 ▌rectangle▐
265 ▙▄▄▄▄▄▄▄▄▄▟
266
267
268 -------------------------------------------------
269
270 -> # Suspend your presentation for hands-on examples <-
271
272 Use *Ctrl + z* to suspend the presentation.
273
274 Use *fg* to resume it.
275
276 -------------------------------------------------
277
278 -> # Convert your presentation to PDF <-
279
280 To publish your presentation later on, you may
281 want to convert it to PDF.
282
283 This can be achieved by two additional tools:
284
285 \- *markdown* to convert to HTML
286 \- *wkhtmltopdf* to convert from HTML to PDF
287
288 After installing them, you can simply type:
289
290 $ markdown sample.md | wkhtmltopdf - sample.pdf
291
292 -------------------------------------------------
293
294 -> ## Last words <-
295
296 I hope you like *mdp*.
297
298 If you observe strange behavior, feel free to
299 open an issue on [GitHub](https://github.com/visit1985/mdp).
0 #
1 # Makefile
2 # Copyright (C) 2015 Michael Goehler
3 #
4 # This file is part of mdp.
5 #
6 # This program is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation, either version 3 of the License, or
9 # (at your option) any later version.
10 #
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
18 #
19
20 UNAME_S := $(shell uname -s 2>/dev/null || echo not)
21
22 SOURCES = $(wildcard *.c)
23 OBJECTS = $(SOURCES:.c=.o)
24 CFLAGS ?= -O3
25 CFLAGS += -Wall
26 CPPFLAGS += -I../include
27
28 ifeq ($(DEBUG),1)
29 CFLAGS := -O0 -Wall -g
30 endif
31
32 ifeq ($(OS),Windows_NT)
33 ifeq (,$(findstring CYGWIN,$(UNAME_S)))
34 CPPFLAGS += -DWIN32
35 else
36 CPPFLAGS += -DCYGWIN
37 endif
38 endif
39
40 ifeq ($(UNAME_S),Linux)
41 LSB_RELEASE := $(shell lsb_release -si 2>/dev/null || echo not)
42 ifneq ($(filter $(LSB_RELEASE),Debian Ubuntu LinuxMint CrunchBang),)
43 CPPFLAGS += -I/usr/include/ncursesw
44 endif
45 endif
46
47 all: $(OBJECTS)
48
49 clean:
50 $(RM) $(OBJECTS)
51
0 /*
1 * An implementation of a char stack in heap memory.
2 * Copyright (C) 2015 Michael Goehler
3 *
4 * This file is part of mdp.
5 *
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 *
19 */
20
21 #include <wchar.h>
22 #include <stdio.h> // fprintf
23 #include <stdlib.h> // malloc, realloc
24
25 #include "cstack.h"
26
27 cstack_t *cstack_init() {
28 cstack_t *stack = NULL;
29 if((stack = malloc(sizeof(cstack_t))) != NULL) {
30 stack->content = NULL;
31 stack->alloc = stack->size = 0;
32 stack->head = -1;
33 stack->push = cstack_push;
34 stack->pop = cstack_pop;
35 stack->top = cstack_top;
36 stack->empty = cstack_empty;
37 stack->delete = cstack_delete;
38 } else {
39 fprintf(stderr, "%s\n", "cstack_init() failed to allocate memory.");
40 exit(EXIT_FAILURE);
41 }
42 return stack;
43 }
44
45 void cstack_push(cstack_t *self, wchar_t c) {
46 if(self->size + sizeof(c) > self->alloc) {
47 self->alloc += (sizeof(wchar_t));
48 if((self->content = realloc(self->content, self->alloc)) == NULL) {
49 fprintf(stderr, "%s\n", "cstack_push() failed to reallocate memory.");
50 exit(EXIT_FAILURE);
51 }
52 }
53 self->content[++self->head] = c;
54 self->size += (sizeof(wchar_t));
55 }
56
57 wchar_t cstack_pop(cstack_t *self) {
58 self->size -= (sizeof(wchar_t));
59 return self->content[self->head--];
60 }
61
62 bool cstack_top(cstack_t *self, wchar_t c) {
63 return self->head >= 0 && self->content[self->head] == c;
64 }
65
66 bool cstack_empty(cstack_t *self) {
67 return self->head == -1;
68 }
69
70 void cstack_delete(cstack_t *self) {
71 free(self->content);
72 free(self);
73 }
0 /*
1 * An implementation of expandable c strings in heap memory.
2 * Copyright (C) 2015 Michael Goehler
3 *
4 * This file is part of mdp.
5 *
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 *
19 */
20
21 #include <wchar.h> // wcslen, wcscat, wmemmove
22 #include <stdio.h> // fprintf
23 #include <stdlib.h> // malloc, realloc
24
25 #include "cstring.h"
26
27 cstring_t *cstring_init() {
28 cstring_t *x = NULL;
29 if((x = malloc(sizeof(cstring_t))) != NULL) {
30 x->value = NULL;
31 x->size = x->alloc = 0;
32 x->expand = cstring_expand;
33 x->expand_arr = cstring_expand_arr;
34 x->strip = cstring_strip;
35 x->reset = cstring_reset;
36 x->delete = cstring_delete;
37 } else {
38 fprintf(stderr, "%s\n", "cstring_init() failed to allocate memory.");
39 exit(EXIT_FAILURE);
40 }
41 return x;
42 }
43
44 void cstring_expand(cstring_t *self, wchar_t x) {
45 if((self->size + 2) * sizeof(wchar_t) > self->alloc) {
46 self->alloc += (REALLOC_ADD * sizeof(wchar_t));
47 if((self->value = realloc(self->value, self->alloc)) == NULL) {
48 fprintf(stderr, "%s\n", "cstring_expand() failed to reallocate memory.");
49 exit(EXIT_FAILURE);
50 }
51 }
52 self->value[self->size] = x;
53 self->value[self->size+1] = L'\0';
54 self->size = wcslen(self->value);
55 }
56
57 void cstring_expand_arr(cstring_t *self, wchar_t *x) {
58 if((self->size + wcslen(x) + 1) * sizeof(wchar_t) > self->alloc) {
59 self->alloc = ((self->size + wcslen(x) + 1) * sizeof(wchar_t));
60 if((self->value = realloc(self->value, self->alloc)) == NULL) {
61 fprintf(stderr, "%s\n", "cstring_expand_arr() failed to reallocate memory.");
62 exit(EXIT_FAILURE);
63 }
64 }
65 self->value = wcscat(self->value, x);
66 self->size = wcslen(self->value);
67 self->value[self->size+1] = L'\0';
68 }
69
70 void cstring_strip(cstring_t *self, int pos, int len) {
71 if(pos + len >= self->size) {
72 if(pos <= self->size) {
73 self->value[pos] = L'\0';
74 self->size = pos;
75 }
76 return;
77 }
78 wmemmove(&self->value[pos], &self->value[pos+len], self->size - pos - len+1);
79 self->size -= len;
80 }
81
82 void cstring_reset(cstring_t *self) {
83 free(self->value);
84 self->value = NULL;
85 self->size = self->alloc = 0;
86 }
87
88 void cstring_delete(cstring_t *self) {
89 free(self->value);
90 free(self);
91 }
0 /*
1 * mdp -- A command-line based markdown presentation tool.
2 * Copyright (C) 2015 Michael Goehler
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 *
17 */
18
19 #include <errno.h>
20 #include <getopt.h>
21 #include <locale.h> // setlocale
22 #include <stdio.h>
23 #include <stdlib.h>
24 #include <string.h>
25
26 #include "main.h"
27
28 void usage() {
29 fprintf(stderr, "%s", "Usage: mdp [OPTION]... [FILE]\n");
30 fprintf(stderr, "%s", "A command-line based markdown presentation tool.\n\n");
31 fprintf(stderr, "%s", " -d, --debug enable debug messages on STDERR\n");
32 fprintf(stderr, "%s", " add it multiple times to increases debug level\n");
33 fprintf(stderr, "%s", " -f, --nofade disable color fading in 256 color mode\n");
34 fprintf(stderr, "%s", " -h, --help display this help and exit\n");
35 fprintf(stderr, "%s", " -i, --invert swap black and white color\n");
36 fprintf(stderr, "%s", " -t, --notrans disable transparency in transparent terminal\n");
37 fprintf(stderr, "%s", " -s, --noslidenum do not show slide number at the bottom\n");
38 fprintf(stderr, "%s", " -v, --version display the version number and license\n");
39 fprintf(stderr, "%s", " -x, --noslidemax show slide number, but not total number of slides\n");
40 fprintf(stderr, "%s", "\nWith no FILE, or when FILE is -, read standard input.\n\n");
41 exit(EXIT_FAILURE);
42 }
43
44 void version() {
45 printf("mdp %d.%d.%d\n", MDP_VER_MAJOR, MDP_VER_MINOR, MDP_VER_REVISION);
46 printf("Copyright (C) 2015 Michael Goehler\n");
47 printf("License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.\n");
48 printf("This is free software: you are free to change and redistribute it.\n");
49 printf("There is NO WARRANTY, to the extent permitted by law.\n");
50 printf("\nWritten by Michael Goehler and others, see <https://github.com/visit1985/mdp/blob/master/AUTHORS>.\n");
51 exit(EXIT_SUCCESS);
52 }
53
54 int main(int argc, char *argv[]) {
55 int notrans = 0; // disable transparency
56 int nofade = 0; // disable fading
57 int invert = 0; // invert color (black on white)
58 int reload = 0; // reload page N (0 means no reload)
59 int noreload = 1; // reload disabled until we know input is a file
60 int slidenum = 2; // 0:don't show; 1:show #; 2:show #/#
61
62 // define command-line options
63 struct option longopts[] = {
64 { "debug", no_argument, 0, 'd' },
65 { "nofade", no_argument, 0, 'f' },
66 { "help", no_argument, 0, 'h' },
67 { "invert", no_argument, 0, 'i' },
68 { "notrans", no_argument, 0, 't' },
69 { "version", no_argument, 0, 'v' },
70 { "noslidenum", no_argument, 0, 's' },
71 { "noslidemax", no_argument, 0, 'x' },
72 { 0, 0, 0, 0 }
73 };
74
75 // parse command-line options
76 int opt, debug = 0;
77 while ((opt = getopt_long(argc, argv, ":dfhitvsx", longopts, NULL)) != -1) {
78 switch(opt) {
79 case 'd': debug += 1; break;
80 case 'f': nofade = 1; break;
81 case 'h': usage(); break;
82 case 'i': invert = 1; break;
83 case 't': notrans = 1; break;
84 case 'v': version(); break;
85 case 's': slidenum = 0; break;
86 case 'x': slidenum = 1; break;
87 case ':': fprintf(stderr, "%s: '%c' requires an argument\n", argv[0], optopt); usage(); break;
88 case '?':
89 default : fprintf(stderr, "%s: option '%c' is invalid\n", argv[0], optopt); usage(); break;
90 }
91 }
92
93 // set locale to that of the environment, so that ncurses properly renders
94 // UTF-8 characters if the system supports it
95 setlocale(LC_CTYPE, "");
96
97 // open file or set input to STDIN
98 char *file = NULL;
99 FILE *input;
100 if (optind < argc) {
101 do {
102 file = argv[optind];
103 } while(++optind < argc);
104
105 if(!strcmp(file, "-")) {
106 input = stdin;
107 } else {
108 input = fopen(file,"r");
109 if(!input) {
110 fprintf(stderr, "%s: %s: %s\n", argv[0], file, strerror(errno));
111 exit(EXIT_FAILURE);
112 }
113 // enable reload because input is a file
114 noreload = 0;
115 }
116 } else {
117 input = stdin;
118 }
119
120 // reload loop
121 do {
122
123 // reopen input file on reload
124 if(noreload == 0 && reload > 0) {
125 if(file) {
126 input = fopen(file,"r");
127 if(!input) {
128 fprintf(stderr, "%s: %s: %s\n", argv[0], file, strerror(errno));
129 exit(EXIT_FAILURE);
130 }
131 } else {
132 fprintf(stderr, "%s: %s\n", argv[0], "no input file");
133 exit(EXIT_FAILURE);
134 }
135 }
136
137 // load deck object from input
138 deck_t *deck;
139 deck = markdown_load(input);
140
141 // close file
142 fclose(input);
143
144 // replace stdin with current tty if input was a pipe
145 // if input was a pipe reload is disabled, so we simply check that
146 if(noreload == 1) {
147 input = freopen("/dev/tty", "rw", stdin);
148 if(!input) {
149 fprintf(stderr, "%s: %s: %s\n", argv[0], "/dev/tty", strerror(errno));
150 exit(EXIT_FAILURE);
151 }
152 }
153
154 if(debug > 0) {
155 markdown_debug(deck, debug);
156 }
157
158 reload = ncurses_display(deck, notrans, nofade, invert, reload, noreload, slidenum);
159
160 free_deck(deck);
161
162 // reload if supported and requested
163 } while(noreload == 0 && reload > 0);
164
165 return EXIT_SUCCESS;
166 }
0 /*
1 * An implementation of markdown objects.
2 * Copyright (C) 2015 Michael Goehler
3 *
4 * This file is part of mdp.
5 *
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 *
19 */
20
21 #include <stdio.h>
22 #include <stdlib.h>
23
24 #include "markdown.h"
25
26 line_t *new_line() {
27 line_t *x = malloc(sizeof(line_t));
28 x->text = NULL;
29 x->prev = x->next = NULL;
30 x->bits = x->length = x->offset = 0;
31 return x;
32 }
33
34 line_t *next_line(line_t *prev) {
35 line_t *x = new_line();
36 x->prev = prev;
37 prev->next = x;
38 return x;
39 }
40
41 slide_t *new_slide() {
42 slide_t *x = malloc(sizeof(slide_t));
43 x->line = NULL;
44 x->prev = x->next = NULL;
45 x->lines = x->stop = 0;
46 return x;
47 }
48
49 slide_t *next_slide(slide_t *prev) {
50 slide_t *x = new_slide();
51 x->prev = prev;
52 prev->next = x;
53 return x;
54 }
55
56 deck_t *new_deck() {
57 deck_t *x = malloc(sizeof(deck_t));
58 x->header = NULL;
59 x->slide = new_slide();
60 x->slides = x->headers = 0;
61 return x;
62 }
63
64 void free_line(line_t *line) {
65 line_t *next;
66 while (line) {
67 next = line->next;
68 if(line->text)
69 (line->text->delete)(line->text);
70 free(line);
71 line = next;
72 }
73 }
74
75 void free_deck(deck_t *deck) {
76 slide_t *slide, *next;
77 if (deck == NULL)
78 return;
79 slide = deck->slide;
80 while (slide) {
81 free_line(slide->line);
82 next = slide->next;
83 free(slide);
84 slide = next;
85 }
86 free_line(deck->header);
87 free(deck);
88 }
0 /*
1 * Functions necessary to parse a file and transform its content into
2 * a deck of slides containing lines. All based on markdown formating
3 * rules.
4 * Copyright (C) 2015 Michael Goehler
5 *
6 * This file is part of mdp.
7 *
8 * This program is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation, either version 3 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 *
21 */
22
23 #include <ctype.h>
24 #include <errno.h>
25 #include <stdio.h>
26 #include <stdlib.h>
27 #include <wchar.h>
28 #include <wctype.h>
29 #include <string.h>
30
31 #include "parser.h"
32
33 deck_t *markdown_load(FILE *input) {
34
35 wchar_t c = L'\0'; // char
36 int i = 0; // increment
37 int hc = 0; // header count
38 int lc = 0; // line count
39 int sc = 1; // slide count
40 int bits = 0; // markdown bits
41 int prev = 0; // markdown bits of previous line
42
43 deck_t *deck = new_deck();
44 slide_t *slide = deck->slide;
45 line_t *line = NULL;
46 line_t *tmp = NULL;
47 cstring_t *text = cstring_init();
48
49 // initialize bits as empty line
50 SET_BIT(bits, IS_EMPTY);
51
52 while ((c = fgetwc(input)) != WEOF) {
53 if (ferror(input)) {
54 fprintf(stderr, "markdown_load() failed to read input: %s\n", strerror(errno));
55 exit(EXIT_FAILURE);
56 }
57
58 if(c == L'\n') {
59
60 // markdown analyse
61 prev = bits;
62 bits = markdown_analyse(text, prev);
63
64 // if first line in file is markdown hr
65 if(!line && CHECK_BIT(bits, IS_HR)) {
66
67 // clear text
68 (text->reset)(text);
69
70 } else if(line && CHECK_BIT(bits, IS_STOP)) {
71
72 // set stop bit on last line
73 SET_BIT(line->bits, IS_STOP);
74
75 // clear text
76 (text->reset)(text);
77
78 // if text is markdown hr
79 } else if(CHECK_BIT(bits, IS_HR) &&
80 CHECK_BIT(line->bits, IS_EMPTY)) {
81
82 slide->lines = lc;
83
84 // clear text
85 (text->reset)(text);
86
87 // create next slide
88 slide = next_slide(slide);
89 sc++;
90
91 } else if(CHECK_BIT(bits, IS_TILDE_CODE) && CHECK_BIT(bits, IS_EMPTY)) {
92 // remove tilde code markers
93 (text->reset)(text);
94
95 } else {
96
97 // if slide ! has line
98 if(!slide->line || !line) {
99
100 // create new line
101 line = new_line();
102 slide->line = line;
103 lc = 1;
104
105 } else {
106
107 // create next line
108 line = next_line(line);
109 lc++;
110
111 }
112
113 // add text to line
114 line->text = text;
115
116 // add bits to line
117 line->bits = bits;
118
119 // calc offset
120 line->offset = next_nonblank(text, 0);
121
122 // adjust line length dynamicaly - excluding markup
123 if(line->text->value)
124 adjust_line_length(line);
125
126 // new text
127 text = cstring_init();
128 }
129
130 } else if(c == L'\t') {
131
132 // expand tab to spaces
133 for (i = 0; i < EXPAND_TABS; i++) {
134 (text->expand)(text, L' ');
135 }
136
137 } else if(c == L'\\') {
138
139 // add char to line
140 (text->expand)(text, c);
141
142 // if !IS_CODE add next char to line
143 // and do not increase line count
144 if(next_nonblank(text, 0) < CODE_INDENT) {
145
146 c = fgetwc(input);
147 (text->expand)(text, c);
148 }
149
150 } else if(iswprint(c) || iswspace(c)) {
151
152 // add char to line
153 (text->expand)(text, c);
154 }
155 }
156 (text->delete)(text);
157
158 slide->lines = lc;
159 deck->slides = sc;
160
161 // detect header
162 line = deck->slide->line;
163 if(line && line->text->size > 0 && line->text->value[0] == L'%') {
164
165 // assign header to deck
166 deck->header = line;
167
168 // find first non-header line
169 while(line && line->text->size > 0 && line->text->value[0] == L'%') {
170 hc++;
171 line = line->next;
172 }
173
174 // only split header if any non-header line is found
175 if(line) {
176
177 // split linked list
178 line->prev->next = NULL;
179 line->prev = NULL;
180
181 // remove header lines from slide
182 deck->slide->line = line;
183
184 // adjust counts
185 deck->headers += hc;
186 deck->slide->lines -= hc;
187 } else {
188
189 // remove header from deck
190 deck->header = NULL;
191 }
192 }
193
194 slide = deck->slide;
195 while(slide) {
196 line = slide->line;
197
198 // ignore mdpress format attributes
199 if(line &&
200 slide->lines > 1 &&
201 !CHECK_BIT(line->bits, IS_EMPTY) &&
202 line->text->value[line->offset] == L'=' &&
203 line->text->value[line->offset + 1] == L' ') {
204
205 // remove line from linked list
206 slide->line = line->next;
207 line->next->prev = NULL;
208
209 // maintain loop condition
210 tmp = line;
211 line = line->next;
212
213 // adjust line count
214 slide->lines -= 1;
215
216 // delete line
217 (tmp->text->delete)(tmp->text);
218 free(tmp);
219 }
220
221 while(line) {
222 // combine underlined H1/H2 in single line
223 if((CHECK_BIT(line->bits, IS_H1) ||
224 CHECK_BIT(line->bits, IS_H2)) &&
225 CHECK_BIT(line->bits, IS_EMPTY) &&
226 line->prev &&
227 !CHECK_BIT(line->prev->bits, IS_EMPTY)) {
228
229
230 // remove line from linked list
231 line->prev->next = line->next;
232 if(line->next)
233 line->next->prev = line->prev;
234
235 // set bits on previous line
236 if(CHECK_BIT(line->bits, IS_H1)) {
237 SET_BIT(line->prev->bits, IS_H1);
238 } else {
239 SET_BIT(line->prev->bits, IS_H2);
240 }
241
242 // adjust line count
243 slide->lines -= 1;
244
245 // maintain loop condition
246 tmp = line;
247 line = line->prev;
248
249 // delete line
250 (tmp->text->delete)(tmp->text);
251 free(tmp);
252
253 // pass enclosing flag IS_UNORDERED_LIST_3
254 // to nested levels for unordered lists
255 } else if(CHECK_BIT(line->bits, IS_UNORDERED_LIST_3)) {
256 tmp = line->next;
257 line_t *list_last_level_3 = line;
258
259 while(tmp &&
260 CHECK_BIT(tmp->bits, IS_UNORDERED_LIST_3)) {
261 if(CHECK_BIT(tmp->bits, IS_UNORDERED_LIST_3)) {
262 list_last_level_3 = tmp;
263 }
264 tmp = tmp->next;
265 }
266
267 for(tmp = line; tmp != list_last_level_3; tmp = tmp->next) {
268 SET_BIT(tmp->bits, IS_UNORDERED_LIST_3);
269 }
270
271 // pass enclosing flag IS_UNORDERED_LIST_2
272 // to nested levels for unordered lists
273 } else if(CHECK_BIT(line->bits, IS_UNORDERED_LIST_2)) {
274 tmp = line->next;
275 line_t *list_last_level_2 = line;
276
277 while(tmp &&
278 (CHECK_BIT(tmp->bits, IS_UNORDERED_LIST_2) ||
279 CHECK_BIT(tmp->bits, IS_UNORDERED_LIST_3))) {
280 if(CHECK_BIT(tmp->bits, IS_UNORDERED_LIST_2)) {
281 list_last_level_2 = tmp;
282 }
283 tmp = tmp->next;
284 }
285
286 for(tmp = line; tmp != list_last_level_2; tmp = tmp->next) {
287 SET_BIT(tmp->bits, IS_UNORDERED_LIST_2);
288 }
289
290 // pass enclosing flag IS_UNORDERED_LIST_1
291 // to nested levels for unordered lists
292 } else if(CHECK_BIT(line->bits, IS_UNORDERED_LIST_1)) {
293 tmp = line->next;
294 line_t *list_last_level_1 = line;
295
296 while(tmp &&
297 (CHECK_BIT(tmp->bits, IS_UNORDERED_LIST_1) ||
298 CHECK_BIT(tmp->bits, IS_UNORDERED_LIST_2) ||
299 CHECK_BIT(tmp->bits, IS_UNORDERED_LIST_3))) {
300 if(CHECK_BIT(tmp->bits, IS_UNORDERED_LIST_1)) {
301 list_last_level_1 = tmp;
302 }
303 tmp = tmp->next;
304 }
305
306 for(tmp = line; tmp != list_last_level_1; tmp = tmp->next) {
307 SET_BIT(tmp->bits, IS_UNORDERED_LIST_1);
308 }
309 }
310
311 line = line->next;
312 }
313 slide = slide->next;
314 }
315
316 return deck;
317 }
318
319 int markdown_analyse(cstring_t *text, int prev) {
320
321 // static variables can not be redeclaired, but changed outside of a declaration
322 // the program remembers their value on every function calls
323 static int unordered_list_level = 0;
324 static int unordered_list_level_offset[] = {-1, -1, -1, -1};
325 static int num_tilde_characters = 0;
326
327 int i = 0; // increment
328 int bits = 0; // markdown bits
329 int offset = 0; // text offset
330 int eol = 0; // end of line
331
332 int equals = 0, hashes = 0,
333 stars = 0, minus = 0,
334 spaces = 0, other = 0; // special character counts
335
336 const int unordered_list_offset = unordered_list_level_offset[unordered_list_level];
337
338 // return IS_EMPTY on null pointers
339 if(!text || !text->value) {
340 SET_BIT(bits, IS_EMPTY);
341 return bits;
342 }
343
344 // count leading spaces
345 offset = next_nonblank(text, 0);
346
347 // IS_TILDE_CODE
348 if (wcsncmp(text->value, L"~~~", 3) == 0) {
349 int tildes_in_line = next_nontilde(text, 0);
350 if (tildes_in_line >= num_tilde_characters) {
351 if (num_tilde_characters > 0) {
352 num_tilde_characters = 0;
353 } else {
354 num_tilde_characters = tildes_in_line;
355 }
356 SET_BIT(bits, IS_EMPTY);
357 SET_BIT(bits, IS_TILDE_CODE);
358 return bits;
359 }
360 }
361
362 if (num_tilde_characters > 0) {
363 SET_BIT(bits, IS_CODE);
364 SET_BIT(bits, IS_TILDE_CODE);
365 return bits;
366 }
367
368 // IS_STOP
369 if((offset < CODE_INDENT || !CHECK_BIT(prev, IS_CODE)) &&
370 (!wcsncmp(&text->value[offset], L"<br>", 4) ||
371 !wcsncmp(&text->value[offset], L"<BR>", 4) ||
372 !wcsncmp(&text->value[offset], L"^", 1))) {
373 SET_BIT(bits, IS_STOP);
374 return bits;
375 }
376
377 // strip trailing spaces
378 for(eol = text->size; eol > offset && iswspace(text->value[eol - 1]); eol--);
379
380 // IS_UNORDERED_LIST_#
381 if(text->size >= offset + 2 &&
382 (text->value[offset] == L'*' || text->value[offset] == L'-') &&
383 iswspace(text->value[offset + 1])) {
384
385 // if different from last lines offset
386 if(offset != unordered_list_offset) {
387
388 // test if offset matches a lower indent level
389 for(i = unordered_list_level; i >= 0; i--) {
390 if(unordered_list_level_offset[i] == offset) {
391 unordered_list_level = i;
392 break;
393 }
394 }
395 // if offset doesn't match any previously stored indent level
396 if(i != unordered_list_level) {
397 unordered_list_level = MIN(unordered_list_level + 1, UNORDERED_LIST_MAX_LEVEL);
398 // memorize the offset as next bigger indent level
399 unordered_list_level_offset[unordered_list_level] = offset;
400 }
401 }
402
403 // if no previous indent level matches, this must be the first line of the list
404 if(unordered_list_level == 0) {
405 unordered_list_level = 1;
406 unordered_list_level_offset[1] = offset;
407 }
408
409 switch(unordered_list_level) {
410 case 1: SET_BIT(bits, IS_UNORDERED_LIST_1); break;
411 case 2: SET_BIT(bits, IS_UNORDERED_LIST_2); break;
412 case 3: SET_BIT(bits, IS_UNORDERED_LIST_3); break;
413 default: break;
414 }
415 }
416
417 if(!CHECK_BIT(bits, IS_UNORDERED_LIST_1) &&
418 !CHECK_BIT(bits, IS_UNORDERED_LIST_2) &&
419 !CHECK_BIT(bits, IS_UNORDERED_LIST_3)) {
420
421 // continue list if indent level is still the same as in previous line
422 if ((CHECK_BIT(prev, IS_UNORDERED_LIST_1) ||
423 CHECK_BIT(prev, IS_UNORDERED_LIST_2) ||
424 CHECK_BIT(prev, IS_UNORDERED_LIST_3)) &&
425 offset >= unordered_list_offset) {
426
427 switch(unordered_list_level) {
428 case 1: SET_BIT(bits, IS_UNORDERED_LIST_1); break;
429 case 2: SET_BIT(bits, IS_UNORDERED_LIST_2); break;
430 case 3: SET_BIT(bits, IS_UNORDERED_LIST_3); break;
431 default: break;
432 }
433
434 // this line extends the previous list item
435 SET_BIT(bits, IS_UNORDERED_LIST_EXT);
436
437 // or reset indent level
438 } else {
439 unordered_list_level = 0;
440 }
441 }
442
443 if(!CHECK_BIT(bits, IS_UNORDERED_LIST_1) &&
444 !CHECK_BIT(bits, IS_UNORDERED_LIST_2) &&
445 !CHECK_BIT(bits, IS_UNORDERED_LIST_3)) {
446
447 // IS_CODE
448 if(offset >= CODE_INDENT &&
449 (CHECK_BIT(prev, IS_EMPTY) ||
450 CHECK_BIT(prev, IS_CODE) ||
451 CHECK_BIT(prev, IS_STOP))) {
452 SET_BIT(bits, IS_CODE);
453
454 } else {
455
456 // IS_QUOTE
457 if(text->value[offset] == L'>') {
458 SET_BIT(bits, IS_QUOTE);
459 }
460
461 // IS_CENTER
462 if(text->size >= offset + 3 &&
463 text->value[offset] == L'-' &&
464 text->value[offset + 1] == L'>' &&
465 iswspace(text->value[offset + 2])) {
466 SET_BIT(bits, IS_CENTER);
467
468 // remove start tag
469 (text->strip)(text, offset, 3);
470 eol -= 3;
471
472 if(text->size >= offset + 3 &&
473 text->value[eol - 1] == L'-' &&
474 text->value[eol - 2] == L'<' &&
475 iswspace(text->value[eol - 3])) {
476
477 // remove end tags
478 (text->strip)(text, eol - 3, 3);
479
480 // adjust end of line
481 for(eol = text->size; eol > offset && iswspace(text->value[eol - 1]); eol--);
482
483 }
484 }
485
486 for(i = offset; i < eol; i++) {
487
488 if(iswspace(text->value[i])) {
489 spaces++;
490
491 } else {
492 switch(text->value[i]) {
493 case L'=': equals++; break;
494 case L'#': hashes++; break;
495 case L'*': stars++; break;
496 case L'-': minus++; break;
497 case L'\\': other++; i++; break;
498 default: other++; break;
499 }
500 }
501 }
502
503 // IS_H1
504 if(equals > 0 &&
505 hashes + stars + minus + spaces + other == 0) {
506 SET_BIT(bits, IS_H1);
507 }
508 if(text->value[offset] == L'#' &&
509 iswspace(text->value[offset+1])) {
510 SET_BIT(bits, IS_H1);
511 SET_BIT(bits, IS_H1_ATX);
512 }
513
514 // IS_H2
515 if(minus > 0 &&
516 equals + hashes + stars + spaces + other == 0) {
517 SET_BIT(bits, IS_H2);
518 }
519 if(text->value[offset] == L'#' &&
520 text->value[offset+1] == L'#' &&
521 iswspace(text->value[offset+2])) {
522 SET_BIT(bits, IS_H2);
523 SET_BIT(bits, IS_H2_ATX);
524 }
525
526 // IS_HR
527 if((minus >= 3 && equals + hashes + stars + other == 0) ||
528 (stars >= 3 && equals + hashes + minus + other == 0)) {
529
530 SET_BIT(bits, IS_HR);
531 }
532
533 // IS_EMPTY
534 if(other == 0) {
535 SET_BIT(bits, IS_EMPTY);
536 }
537 }
538 }
539
540 return bits;
541 }
542
543 void markdown_debug(deck_t *deck, int debug) {
544
545 int sc = 0; // slide count
546 int lc = 0; // line count
547
548 int offset;
549 line_t *header;
550
551 if(debug == 1) {
552 fwprintf(stderr, L"headers: %i\nslides: %i\n", deck->headers, deck->slides);
553
554 } else if(debug > 1) {
555
556 // print header to STDERR
557 if(deck->header) {
558 header = deck->header;
559 while(header &&
560 header->length > 0 &&
561 header->text->value[0] == L'%') {
562
563 // skip descriptor word (e.g. %title:)
564 offset = next_blank(header->text, 0) + 1;
565
566 fwprintf(stderr, L"header: %S\n", &header->text->value[offset]);
567 header = header->next;
568 }
569 }
570 }
571
572 slide_t *slide = deck->slide;
573 line_t *line;
574
575 // print slide/line count to STDERR
576 while(slide) {
577 sc++;
578
579 if(debug == 1) {
580 fwprintf(stderr, L" slide %i: %i lines\n", sc, slide->lines);
581
582 } else if(debug > 1) {
583
584 // also print bits and line length
585 fwprintf(stderr, L" slide %i:\n", sc);
586 line = slide->line;
587 lc = 0;
588 while(line) {
589 lc++;
590 fwprintf(stderr, L" line %i: bits = %i, length = %i\n", lc, line->bits, line->length);
591 line = line->next;
592 }
593 }
594
595 slide = slide->next;
596 }
597 }
598
599 void adjust_line_length(line_t *line) {
600 int l = 0;
601 const static wchar_t *special = L"\\*_`"; // list of interpreted chars
602 const wchar_t *c = &line->text->value[line->offset];
603 cstack_t *stack = cstack_init();
604
605 // for each char in line
606 for(; *c; c++) {
607 // if char is in special char list
608 if(wcschr(special, *c)) {
609
610 // closing special char (or second backslash)
611 if((stack->top)(stack, *c)) {
612 if(*c == L'\\') l++;
613 (stack->pop)(stack);
614
615 // treat special as regular char
616 } else if((stack->top)(stack, L'\\')) {
617 l++;
618 (stack->pop)(stack);
619
620 // opening special char
621 } else {
622 (stack->push)(stack, *c);
623 }
624
625 } else {
626 // remove backslash from stack
627 if((stack->top)(stack, L'\\'))
628 (stack->pop)(stack);
629 l++;
630 }
631 }
632
633 if(CHECK_BIT(line->bits, IS_H1_ATX))
634 l -= 2;
635 if(CHECK_BIT(line->bits, IS_H2_ATX))
636 l -= 3;
637
638 line->length = l;
639
640 (stack->delete)(stack);
641 }
642
643 int next_nonblank(cstring_t *text, int i) {
644 while ((i < text->size) && iswspace((text->value)[i]))
645 i++;
646
647 return i;
648 }
649
650 int prev_blank(cstring_t *text, int i) {
651 while ((i > 0) && !iswspace((text->value)[i]))
652 i--;
653
654 return i;
655 }
656
657 int next_blank(cstring_t *text, int i) {
658 while ((i < text->size) && !iswspace((text->value)[i]))
659 i++;
660
661 return i;
662 }
663
664 int next_word(cstring_t *text, int i) {
665 return next_nonblank(text, next_blank(text, i));
666 }
667
668 int next_nontilde(cstring_t *text, int i) {
669 while ((i < text->size) && text->value[i] == L'~')
670 i++;
671
672 return i;
673 }
674
0 /*
1 * Functions necessary to handle pandoc URLs.
2 * Copyright (C) 2015 Michael Goehler
3 *
4 * This file is part of mdp.
5 *
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 *
19 */
20
21 #include <stdlib.h>
22 #include <assert.h>
23 #include <wchar.h>
24 #include <stdio.h>
25
26 #include "url.h"
27
28 static void url_del_elem(url_t *elem);
29 static void url_print(url_t *u);
30
31 static url_t *list;
32 static int index_max;
33 static int init_ok;
34
35 void url_init(void) {
36 list = NULL;
37 index_max = 0;
38 init_ok = 1;
39 }
40
41 int url_add(const wchar_t *link_name, int link_name_length, const wchar_t *target, int target_length, int x, int y) {
42 if (!init_ok) return -1;
43
44 url_t *tmp = NULL;
45 int i = 0;
46
47 if (list) {
48 tmp = list;
49 while (tmp->next) {
50 tmp = tmp->next;
51 i++;
52 }
53 tmp->next = malloc(sizeof(url_t));
54 assert(tmp->next);
55 tmp = tmp->next;
56 } else {
57 list = malloc(sizeof(url_t));
58 tmp = list;
59 assert(tmp);
60 }
61
62 tmp -> link_name = calloc(link_name_length+1, sizeof(wchar_t));
63 assert(tmp->link_name);
64 wcsncpy(tmp->link_name, link_name, link_name_length);
65 tmp->link_name[link_name_length] = '\0';
66
67 tmp->target = calloc(target_length+1, sizeof(wchar_t));
68 assert(tmp->target);
69 wcsncpy(tmp->target, target, target_length);
70 tmp->target[target_length] = '\0';
71
72 tmp->x = x;
73 tmp->y = y;
74 tmp->next = NULL;
75
76 index_max++;
77
78 return index_max-1;
79 }
80
81 wchar_t * url_get_target(int index) {
82 if (!init_ok) return NULL;
83
84 url_t *tmp = list;
85
86 if (!tmp) return NULL;
87
88 while (index > 0 && tmp && tmp->next) {
89 tmp = tmp->next;
90 index--;
91 }
92
93 if (!index) {
94 return tmp->target;
95 } else return NULL;
96 }
97
98 wchar_t * url_get_name(int index) {
99 url_t *tmp = list;
100
101 while (index > 0 && tmp && tmp->next) {
102 tmp = tmp->next;
103 index --;
104 }
105
106 if (!index) {
107 return tmp->link_name;
108 } else return NULL;
109 }
110
111 void url_purge() {
112 url_del_elem(list);
113 list = NULL;
114 index_max = 0;
115 init_ok = 0;
116 }
117
118 static void url_del_elem(url_t *elem) {
119 if (!elem) return;
120
121 if (elem->next) {
122 url_del_elem(elem->next);
123 elem->next = NULL;
124 }
125
126 if (elem->target) {
127 free(elem->target);
128 elem->target = NULL;
129 }
130
131 if (elem->link_name) {
132 free(elem->link_name);
133 elem->link_name = NULL;
134 }
135
136 free(elem);
137 }
138
139 void url_dump(void) {
140 if (!list) return;
141
142 url_t *tmp = list;
143
144 while (tmp) {
145 url_print(tmp);
146 if (tmp->next)
147 tmp = tmp->next;
148 else break;
149 }
150 }
151
152 static void url_print(url_t *u) {
153 printf("url_t @ %p\n", u);
154 }
155
156 int url_get_amount(void) {
157 return index_max;
158 }
159
160 int url_count_inline(const wchar_t *line) {
161 int count = 0;
162 const wchar_t *i = line;
163
164 for (; *i; i++) {
165 if (*i == '\\') {
166 i++;
167 } else if ( *i == '[' && *(i+1) != ']') {
168 while (*i && *i != ']') i++;
169 i++;
170 if (*i == '(' && wcschr(i, ')')) {
171 count ++;
172 i = wcschr(i, ')');
173 }
174 }
175 }
176
177 return count;
178 }
179
180 int url_len_inline(const wchar_t *value) {
181 int count = 0;
182 const wchar_t *i = value;
183
184 for (; *i; i++) {
185 if (*i == '\\') {
186 i++;
187 } else if ( *i == '[' && *(i+1) != ']') {
188 while (*i && *i != ']') i++;
189 i++;
190 if (*i == '(' && wcschr(i, ')')) {
191 while (*i && *i != ')') {
192 count++;
193 i++;
194 }
195 }
196 }
197 }
198
199 return count;
200 }
0 /*
1 * Functions necessary to display a deck of slides in different color modes
2 * using ncurses. Only white, red, and blue are supported, as they can be
3 * faded in 256 color mode.
4 * Copyright (C) 2015 Michael Goehler
5 *
6 * This file is part of mdp.
7 *
8 * This program is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation, either version 3 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 *
21 */
22
23 #include <ctype.h> // isalnum
24 #include <wchar.h> // wcschr
25 #include <wctype.h> // iswalnum
26 #include <string.h> // strcpy
27 #include <unistd.h> // usleep
28 #include "viewer.h"
29
30 // color ramp for fading from black to color
31 static short white_ramp[24] = { 16, 232, 233, 234, 235, 236,
32 237, 238, 239, 240, 241, 242,
33 244, 245, 246, 247, 248, 249,
34 250, 251, 252, 253, 254, 255 };
35
36 static short blue_ramp[24] = { 16, 17, 17, 18, 18, 19,
37 19, 20, 20, 21, 27, 33,
38 32, 39, 38, 45, 44, 44,
39 81, 81, 51, 51, 123, 123 };
40
41 static short red_ramp[24] = { 16, 52, 52, 53, 53, 89,
42 89, 90, 90, 126, 127, 127,
43 163, 163, 164, 164, 200, 200,
44 201, 201, 207, 207, 213, 213 };
45
46 // color ramp for fading from white to color
47 static short white_ramp_invert[24] = { 15, 255, 254, 254, 252, 251,
48 250, 249, 248, 247, 246, 245,
49 243, 242, 241, 240, 239, 238,
50 237, 236, 235, 234, 233, 232};
51
52 static short blue_ramp_invert[24] = { 15, 231, 231, 195, 195, 159,
53 159, 123, 123, 87, 51, 44,
54 45, 38, 39, 32, 33, 33,
55 26, 26, 27, 27, 21, 21};
56
57 static short red_ramp_invert[24] = { 15, 231, 231, 224, 224, 225,
58 225, 218, 218, 219, 212, 213,
59 206, 207, 201, 200, 199, 199,
60 198, 198, 197, 197, 196, 196};
61
62 int ncurses_display(deck_t *deck, int notrans, int nofade, int invert, int reload, int noreload, int slidenum) {
63
64 int c = 0; // char
65 int i = 0; // iterate
66 int l = 0; // line number
67 int lc = 0; // line count
68 int sc = 1; // slide count
69 int colors = 0; // amount of colors supported
70 int fade = 0; // disable color fading by default
71 int trans = -1; // enable transparency if term supports it
72 int max_lines = 0; // max lines per slide
73 int max_cols = 0; // max columns per line
74 int offset; // text offset
75 int stop = 0; // passed stop bits per slide
76
77 // header line 1 is displayed at the top
78 int bar_top = (deck->headers > 0) ? 1 : 0;
79 // header line 2 is displayed at the bottom
80 // anyway we display the slide number at the bottom
81 int bar_bottom = (slidenum || deck->headers > 1)? 1 : 0;
82
83 slide_t *slide = deck->slide;
84 line_t *line;
85
86 // init ncurses
87 initscr();
88
89 while(slide) {
90 lc = 0;
91 line = slide->line;
92
93 while(line && line->text) {
94
95 if (line->text->value)
96 lc += url_count_inline(line->text->value);
97
98 if (line->text->value)
99 line->length -= url_len_inline(line->text->value);
100
101 if(line->length > COLS) {
102 i = line->length;
103 offset = 0;
104 while(i > COLS) {
105
106 i = prev_blank(line->text, offset + COLS) - offset;
107
108 // single word is > COLS
109 if(!i) {
110 // calculate min_width
111 i = next_blank(line->text, offset + COLS) - offset;
112
113 // disable ncurses
114 endwin();
115
116 // print error
117 fwprintf(stderr, L"Error: Terminal width (%i columns) too small. Need at least %i columns.\n", COLS, i);
118 fwprintf(stderr, L"You may need to shorten some lines by inserting line breaks.\n");
119
120 // no reload
121 return 0;
122 }
123
124 // set max_cols
125 max_cols = MAX(i, max_cols);
126
127 // iterate to next line
128 offset = prev_blank(line->text, offset + COLS);
129 i = line->length - offset;
130 lc++;
131 }
132 // set max_cols one last time
133 max_cols = MAX(i, max_cols);
134 } else {
135 // set max_cols
136 max_cols = MAX(line->length, max_cols);
137 }
138 lc++;
139 line = line->next;
140 }
141
142 max_lines = MAX(lc, max_lines);
143
144 slide = slide->next;
145 }
146
147 // not enough lines
148 if(max_lines + bar_top + bar_bottom > LINES) {
149
150 // disable ncurses
151 endwin();
152
153 // print error
154 fwprintf(stderr, L"Error: Terminal height (%i lines) too small. Need at least %i lines.\n", LINES, max_lines + bar_top + bar_bottom);
155 fwprintf(stderr, L"You may need to add additional horizontal rules (---) to split your file in shorter slides.\n");
156
157 // no reload
158 return 0;
159 }
160
161 // disable cursor
162 curs_set(0);
163
164 // disable output of keyboard typing
165 noecho();
166
167 // make getch() process one char at a time
168 cbreak();
169
170 // enable arrow keys
171 keypad(stdscr,TRUE);
172
173 // set colors
174 if(has_colors() == TRUE) {
175 start_color();
176 use_default_colors();
177
178 // 256 color mode
179 if(COLORS == 256) {
180
181 if(notrans) {
182 if(invert) {
183 trans = 15; // white in 256 color mode
184 } else {
185 trans = 16; // black in 256 color mode
186 }
187 }
188
189 if(invert) {
190 init_pair(CP_WHITE, 232, trans);
191 init_pair(CP_BLUE, 21, trans);
192 init_pair(CP_RED, 196, trans);
193 init_pair(CP_BLACK, 15, 232);
194 } else {
195 init_pair(CP_WHITE, 255, trans);
196 init_pair(CP_BLUE, 123, trans);
197 init_pair(CP_RED, 213, trans);
198 init_pair(CP_BLACK, 16, 255);
199 }
200 init_pair(CP_YELLOW, 208, trans);
201
202 // enable color fading
203 if(!nofade)
204 fade = true;
205
206 // 8 color mode
207 } else {
208
209 if(notrans) {
210 if(invert) {
211 trans = 7; // white in 8 color mode
212 } else {
213 trans = 0; // black in 8 color mode
214 }
215 }
216
217 if(invert) {
218 init_pair(CP_WHITE, 0, trans);
219 init_pair(CP_BLACK, 7, 0);
220 } else {
221 init_pair(CP_WHITE, 7, trans);
222 init_pair(CP_BLACK, 0, 7);
223 }
224 init_pair(CP_BLUE, 4, trans);
225 init_pair(CP_RED, 1, trans);
226 init_pair(CP_YELLOW, 3, trans);
227 }
228
229 colors = 1;
230 }
231
232 // set background color of main window
233 if(colors)
234 wbkgd(stdscr, COLOR_PAIR(CP_YELLOW));
235
236 // setup main window
237 WINDOW *content = newwin(LINES - bar_top - bar_bottom, COLS, 0 + bar_top, 0);
238 if(colors)
239 wbkgd(content, COLOR_PAIR(CP_WHITE));
240
241 slide = deck->slide;
242
243 // find slide to reload
244 while(reload > 1 && reload <= deck->slides) {
245 slide = slide->next;
246 sc++;
247 reload--;
248 }
249
250 // reset reload indicator
251 reload = 0;
252
253 while(slide) {
254
255 url_init();
256
257 // clear windows
258 werase(content);
259 werase(stdscr);
260
261 // always resize window in case terminal geometry has changed
262 wresize(content, LINES - bar_top - bar_bottom, COLS);
263
264 // setup header
265 if(bar_top) {
266 line = deck->header;
267 offset = next_blank(line->text, 0) + 1;
268 // add text to header
269 mvwaddwstr(stdscr,
270 0, (COLS - line->length + offset) / 2,
271 &line->text->value[offset]);
272 }
273
274 // setup footer
275 if(deck->headers > 1) {
276 line = deck->header->next;
277 offset = next_blank(line->text, 0) + 1;
278 switch(slidenum) {
279 case 0: // add text to center footer
280 mvwaddwstr(stdscr,
281 LINES - 1, (COLS - line->length + offset) / 2,
282 &line->text->value[offset]);
283 break;
284 case 1:
285 case 2: // add text to left footer
286 mvwaddwstr(stdscr,
287 LINES - 1, 3,
288 &line->text->value[offset]);
289 break;
290 }
291 }
292
293 // add slide number to right footer
294 switch(slidenum) {
295 case 1: // show slide number only
296 mvwprintw(stdscr,
297 LINES - 1, COLS - int_length(sc) - 3,
298 "%d", sc);
299 break;
300 case 2: // show current slide & number of slides
301 mvwprintw(stdscr,
302 LINES - 1, COLS - int_length(deck->slides) - int_length(sc) - 6,
303 "%d / %d", sc, deck->slides);
304 break;
305 }
306
307 // make header + fooder visible
308 wrefresh(content);
309 wrefresh(stdscr);
310
311 line = slide->line;
312 l = stop = 0;
313
314 // print lines
315 while(line) {
316 add_line(content, l, (COLS - max_cols) / 2, line, max_cols, colors);
317
318 // raise stop counter if we pass a line having a stop bit
319 if(CHECK_BIT(line->bits, IS_STOP))
320 stop++;
321
322 l += (line->length / COLS) + 1;
323 line = line->next;
324
325 // only stop here if we didn't stop here recently
326 if(stop > slide->stop)
327 break;
328 }
329
330 // print pandoc URL references
331 // only if we already printed all lines of the current slide
332 if(!line) {
333 int i, ymax;
334 getmaxyx( content, ymax, i );
335 for (i = 0; i < url_get_amount(); i++) {
336 mvwprintw(content, ymax - url_get_amount() - 1 + i, 3,
337 "[%d] ", i);
338 waddwstr(content, url_get_target(i));
339 }
340 }
341
342 // make content visible
343 wrefresh(content);
344
345 // fade in
346 if(fade)
347 fade_in(content, trans, colors, invert);
348
349 // re-enable fading after any undefined key press
350 if(COLORS == 256 && !nofade)
351 fade = true;
352
353 // wait for user input
354 c = getch();
355
356 // evaluate user input
357 i = 0;
358 switch(c) {
359
360 // show previous slide or stop bit
361 case KEY_UP:
362 case KEY_LEFT:
363 case KEY_PPAGE:
364 case 8: // BACKSPACE (ascii)
365 case 127: // BACKSPACE (xterm)
366 case 263: // BACKSPACE (getty)
367 case 'h':
368 case 'k':
369 if(stop > 1 || (stop == 1 && !line)) {
370 // show current slide again
371 // but stop one stop bit earlier
372 slide->stop--;
373 fade = false;
374 } else {
375 if(slide->prev) {
376 // show previous slide
377 slide = slide->prev;
378 sc--;
379 //stop on first bullet point always
380 if(slide->stop > 0)
381 slide->stop = 0;
382 } else {
383 // do nothing
384 fade = false;
385 }
386 }
387 break;
388
389 // show next slide or stop bit
390 case KEY_DOWN:
391 case KEY_RIGHT:
392 case KEY_NPAGE:
393 case '\n': // ENTER
394 case ' ': // SPACE
395 case 'j':
396 case 'l':
397 if(stop && line) {
398 // show current slide again
399 // but stop one stop bit later (or at end of slide)
400 slide->stop++;
401 fade = false;
402 } else {
403 if(slide->next) {
404 // show next slide
405 slide = slide->next;
406 sc++;
407 } else {
408 // do nothing
409 fade = false;
410 }
411 }
412 break;
413
414 // show slide n
415 case '9':
416 case '8':
417 case '7':
418 case '6':
419 case '5':
420 case '4':
421 case '3':
422 case '2':
423 case '1':
424 i = get_slide_number(c);
425 if(i > 0 && i <= deck->slides) {
426 while(sc != i) {
427 // search forward
428 if(sc < i) {
429 if(slide->next) {
430 slide = slide->next;
431 sc++;
432 }
433 // search backward
434 } else {
435 if(slide->prev) {
436 slide = slide->prev;
437 sc--;
438 }
439 }
440 }
441 } else {
442 // disable fading if slide n doesn't exist
443 fade = false;
444 }
445 break;
446
447 // show first slide
448 case 'g':
449 case KEY_HOME:
450 slide = deck->slide;
451 sc = 1;
452 break;
453
454 // show last slide
455 case 'G':
456 case KEY_END:
457 for(i = sc; i <= deck->slides; i++) {
458 if(slide->next) {
459 slide = slide->next;
460 sc++;
461 }
462 }
463 break;
464
465 // reload
466 case 'r':
467 if(noreload == 0) {
468 // reload slide N
469 reload = sc;
470 slide = NULL;
471 } else {
472 // disable fading if reload is not possible
473 fade = false;
474 }
475 break;
476
477 // quit
478 case 'q':
479 // do not fade out on exit
480 fade = false;
481 // do not reload
482 reload = 0;
483 slide = NULL;
484 break;
485
486 default:
487 // disable fading on undefined key press
488 fade = false;
489 break;
490 }
491
492 // fade out
493 if(fade)
494 fade_out(content, trans, colors, invert);
495
496 url_purge();
497 }
498
499 // disable ncurses
500 endwin();
501
502 // free ncurses memory
503 delwin(content);
504 if(reload == 0)
505 delwin(stdscr);
506
507 // return reload indicator (0 means no reload)
508 return reload;
509 }
510
511 void add_line(WINDOW *window, int y, int x, line_t *line, int max_cols, int colors) {
512
513 if(!line->text->value) {
514 return;
515 }
516
517 int i; // increment
518 int offset = 0; // text offset
519
520 // move the cursor in position
521 wmove(window, y, x);
522
523 // IS_UNORDERED_LIST_3
524 if(CHECK_BIT(line->bits, IS_UNORDERED_LIST_3)) {
525 offset = next_nonblank(line->text, 0);
526 char prompt[13];
527 strcpy(&prompt[0], CHECK_BIT(line->bits, IS_UNORDERED_LIST_1)? " | " : " ");
528 strcpy(&prompt[4], CHECK_BIT(line->bits, IS_UNORDERED_LIST_2)? " | " : " ");
529
530 if(CHECK_BIT(line->bits, IS_UNORDERED_LIST_EXT)) {
531 strcpy(&prompt[8], line->next && CHECK_BIT(line->next->bits, IS_UNORDERED_LIST_3)? " | " : " ");
532 } else {
533 strcpy(&prompt[8], " +- ");
534 offset += 2;
535 }
536
537 wprintw(window,
538 "%s", prompt);
539
540 if(!CHECK_BIT(line->bits, IS_CODE))
541 inline_display(window, &line->text->value[offset], colors);
542
543 // IS_UNORDERED_LIST_2
544 } else if(CHECK_BIT(line->bits, IS_UNORDERED_LIST_2)) {
545 offset = next_nonblank(line->text, 0);
546 char prompt[9];
547 strcpy(&prompt[0], CHECK_BIT(line->bits, IS_UNORDERED_LIST_1)? " | " : " ");
548
549 if(CHECK_BIT(line->bits, IS_UNORDERED_LIST_EXT)) {
550 strcpy(&prompt[4], line->next && CHECK_BIT(line->next->bits, IS_UNORDERED_LIST_2)? " | " : " ");
551 } else {
552 strcpy(&prompt[4], " +- ");
553 offset += 2;
554 }
555
556 wprintw(window,
557 "%s", prompt);
558
559 if(!CHECK_BIT(line->bits, IS_CODE))
560 inline_display(window, &line->text->value[offset], colors);
561
562 // IS_UNORDERED_LIST_1
563 } else if(CHECK_BIT(line->bits, IS_UNORDERED_LIST_1)) {
564 offset = next_nonblank(line->text, 0);
565 char prompt[5];
566
567 if(CHECK_BIT(line->bits, IS_UNORDERED_LIST_EXT)) {
568 strcpy(&prompt[0], line->next && CHECK_BIT(line->next->bits, IS_UNORDERED_LIST_1)? " | " : " ");
569 } else {
570 strcpy(&prompt[0], " +- ");
571 offset += 2;
572 }
573
574 wprintw(window,
575 "%s", prompt);
576
577 if(!CHECK_BIT(line->bits, IS_CODE))
578 inline_display(window, &line->text->value[offset], colors);
579 }
580
581 // IS_CODE
582 if(CHECK_BIT(line->bits, IS_CODE)) {
583
584 if (!CHECK_BIT(line->bits, IS_TILDE_CODE)) {
585 // set static offset for code
586 offset = CODE_INDENT;
587 }
588
589 // reverse color for code blocks
590 if(colors)
591 wattron(window, COLOR_PAIR(CP_BLACK));
592
593 // print whole lines
594 waddwstr(window, &line->text->value[offset]);
595 }
596
597 if(!CHECK_BIT(line->bits, IS_UNORDERED_LIST_1) &&
598 !CHECK_BIT(line->bits, IS_UNORDERED_LIST_2) &&
599 !CHECK_BIT(line->bits, IS_UNORDERED_LIST_3) &&
600 !CHECK_BIT(line->bits, IS_CODE)) {
601
602 // IS_QUOTE
603 if(CHECK_BIT(line->bits, IS_QUOTE)) {
604 while(line->text->value[offset] == '>') {
605 // print a reverse color block
606 if(colors) {
607 wattron(window, COLOR_PAIR(CP_BLACK));
608 wprintw(window, "%s", " ");
609 wattron(window, COLOR_PAIR(CP_WHITE));
610 wprintw(window, "%s", " ");
611 } else {
612 wprintw(window, "%s", ">");
613 }
614
615 // find next quote or break
616 offset++;
617 if(line->text->value[offset] == ' ')
618 offset = next_word(line->text, offset);
619 }
620
621 inline_display(window, &line->text->value[offset], colors);
622 } else {
623
624 // IS_CENTER
625 if(CHECK_BIT(line->bits, IS_CENTER)) {
626 if(line->length < max_cols) {
627 wmove(window, y, x + ((max_cols - line->length) / 2));
628 }
629 }
630
631 // IS_H1 || IS_H2
632 if(CHECK_BIT(line->bits, IS_H1) || CHECK_BIT(line->bits, IS_H2)) {
633
634 // set headline color
635 if(colors)
636 wattron(window, COLOR_PAIR(CP_BLUE));
637
638 // enable underline for H1
639 if(CHECK_BIT(line->bits, IS_H1))
640 wattron(window, A_UNDERLINE);
641
642 // skip hashes
643 while(line->text->value[offset] == '#')
644 offset = next_word(line->text, offset);
645
646 // print whole lines
647 waddwstr(window, &line->text->value[offset]);
648
649 wattroff(window, A_UNDERLINE);
650
651 // no line-wide markdown
652 } else {
653
654 inline_display(window, &line->text->value[offset], colors);
655 }
656 }
657 }
658
659 // fill rest off line with spaces
660 // we only need this if the color is inverted (e.g. code-blocks),
661 // to ensure the background fades too
662 if(CHECK_BIT(line->bits, IS_CODE))
663 for(i = getcurx(window) - x; i < max_cols; i++)
664 wprintw(window, "%s", " ");
665
666 // reset to default color
667 if(colors)
668 wattron(window, COLOR_PAIR(CP_WHITE));
669 wattroff(window, A_UNDERLINE);
670 }
671
672 void inline_display(WINDOW *window, const wchar_t *c, const int colors) {
673 const static wchar_t *special = L"\\*_`!["; // list of interpreted chars
674 const wchar_t *i = c; // iterator
675 const wchar_t *start_link_name, *start_url;
676 int length_link_name, url_num;
677 cstack_t *stack = cstack_init();
678
679
680 // for each char in line
681 for(; *i; i++) {
682
683 // if char is in special char list
684 if(wcschr(special, *i)) {
685
686 // closing special char (or second backslash)
687 // only if not followed by :alnum:
688 if((stack->top)(stack, *i) &&
689 (!iswalnum(i[1]) || *(i + 1) == L'\0' || *i == L'\\')) {
690
691 switch(*i) {
692 // print escaped backslash
693 case L'\\':
694 waddnwstr(window, i, 1);
695 break;
696 // disable highlight
697 case L'*':
698 if(colors)
699 wattron(window, COLOR_PAIR(CP_WHITE));
700 break;
701 // disable underline
702 case L'_':
703 wattroff(window, A_UNDERLINE);
704 break;
705 // disable inline code
706 case L'`':
707 if(colors)
708 wattron(window, COLOR_PAIR(CP_WHITE));
709 break;
710 }
711
712 // remove top special char from stack
713 (stack->pop)(stack);
714
715 // treat special as regular char
716 } else if((stack->top)(stack, L'\\')) {
717 waddnwstr(window, i, 1);
718
719 // remove backslash from stack
720 (stack->pop)(stack);
721
722 // opening special char
723 } else {
724
725 // emphasis or code span can start after new-line or space only
726 // and of cause after another emphasis markup
727 //TODO this condition looks ugly
728 if(i == c ||
729 iswspace(*(i - 1)) ||
730 ((iswspace(*(i - 1)) || *(i - 1) == L'*' || *(i - 1) == L'_') &&
731 ((i - 1) == c || iswspace(*(i - 2)))) ||
732 *i == L'\\') {
733
734 // url in pandoc style
735 if ((*i == L'[' && wcschr(i, L']')) ||
736 (*i == L'!' && *(i + 1) == L'[' && wcschr(i, L']'))) {
737
738 if (*i == L'!') i++;
739
740 if (wcschr(i, L']')[1] == L'(' && wcschr(i, L')')) {
741 i++;
742
743 // turn higlighting and underlining on
744 if (colors)
745 wattron(window, COLOR_PAIR(CP_BLUE));
746 wattron(window, A_UNDERLINE);
747
748 start_link_name = i;
749
750 // print the content of the label
751 // the label is printed as is
752 do {
753 waddnwstr(window, i, 1);
754 i++;
755 } while (*i != L']');
756
757 length_link_name = i - 1 - start_link_name;
758
759 i++;
760 i++;
761
762 start_url = i;
763
764 while (*i != L')') i++;
765
766 url_num = url_add(start_link_name, length_link_name, start_url, i - start_url, 0, 0);
767
768 wprintw(window, " [%d]", url_num);
769
770 // turn highlighting and underlining off
771 wattroff(window, A_UNDERLINE);
772 wattron(window, COLOR_PAIR(CP_WHITE));
773
774 } else {
775 wprintw(window, "[");
776 }
777
778 } else switch(*i) {
779 // enable highlight
780 case L'*':
781 if(colors)
782 wattron(window, COLOR_PAIR(CP_RED));
783 break;
784 // enable underline
785 case L'_':
786 wattron(window, A_UNDERLINE);
787 break;
788 // enable inline code
789 case L'`':
790 if(colors)
791 wattron(window, COLOR_PAIR(CP_BLACK));
792 break;
793 // do nothing for backslashes
794 }
795
796 // push special char to stack
797 (stack->push)(stack, *i);
798
799 } else {
800 waddnwstr(window, i, 1);
801 }
802 }
803
804 } else {
805 // remove backslash from stack
806 if((stack->top)(stack, L'\\'))
807 (stack->pop)(stack);
808
809 // print regular char
810 waddnwstr(window, i, 1);
811 }
812 }
813
814 // pop stack until empty to prevent formated trailing spaces
815 while(!(stack->empty)(stack)) {
816 switch((stack->pop)(stack)) {
817 // disable highlight
818 case L'*':
819 if(colors)
820 wattron(window, COLOR_PAIR(CP_WHITE));
821 break;
822 // disable underline
823 case L'_':
824 wattroff(window, A_UNDERLINE);
825 break;
826 // disable inline code
827 case L'`':
828 if(colors)
829 wattron(window, COLOR_PAIR(CP_WHITE));
830 break;
831 // do nothing for backslashes
832 }
833 }
834
835 (stack->delete)(stack);
836 }
837
838 void fade_out(WINDOW *window, int trans, int colors, int invert) {
839 int i; // increment
840 if(colors && COLORS == 256) {
841 for(i = 22; i >= 0; i--) {
842
843 // dim color pairs
844 if(invert) {
845 init_pair(CP_WHITE, white_ramp_invert[i], trans);
846 init_pair(CP_BLUE, blue_ramp_invert[i], trans);
847 init_pair(CP_RED, red_ramp_invert[i], trans);
848 init_pair(CP_BLACK, 15, white_ramp_invert[i]);
849 } else {
850 init_pair(CP_WHITE, white_ramp[i], trans);
851 init_pair(CP_BLUE, blue_ramp[i], trans);
852 init_pair(CP_RED, red_ramp[i], trans);
853 init_pair(CP_BLACK, 16, white_ramp[i]);
854 }
855
856 // refresh window with new color
857 wrefresh(window);
858
859 // delay for our eyes to recognize the change
860 usleep(FADE_DELAY);
861 }
862 }
863 }
864
865 void fade_in(WINDOW *window, int trans, int colors, int invert) {
866 int i; // increment
867 if(colors && COLORS == 256) {
868 for(i = 0; i <= 23; i++) {
869
870 // brighten color pairs
871 if(invert) {
872 init_pair(CP_WHITE, white_ramp_invert[i], trans);
873 init_pair(CP_BLUE, blue_ramp_invert[i], trans);
874 init_pair(CP_RED, red_ramp_invert[i], trans);
875 init_pair(CP_BLACK, 15, white_ramp_invert[i]);
876 } else {
877 init_pair(CP_WHITE, white_ramp[i], trans);
878 init_pair(CP_BLUE, blue_ramp[i], trans);
879 init_pair(CP_RED, red_ramp[i], trans);
880 init_pair(CP_BLACK, 16, white_ramp[i]);
881 }
882
883 // refresh window with new color
884 wrefresh(window);
885
886 // delay for our eyes to recognize the change
887 usleep(FADE_DELAY);
888 }
889 }
890 }
891
892 int int_length (int val) {
893 int l = 1;
894 while(val > 9) {
895 l++;
896 val /= 10;
897 }
898 return l;
899 }
900
901 int get_slide_number(char init) {
902 int retval = init - '0';
903 char c;
904 // block for tenths of a second when using getch, ERR if no input
905 halfdelay(GOTO_SLIDE_DELAY);
906 while((c = getch()) != ERR) {
907 if (c < '0' || c > '9') {
908 retval = -1;
909 break;
910 }
911 retval = (retval * 10) + (c - '0');
912 }
913 nocbreak(); // cancel half delay mode
914 cbreak(); // go back to cbreak
915 return retval;
916 }
0 %title: UTF-8 Test Presentation
1
2 _Tables:_
3
4 ┍━━━━━━━━━━┯━━━━━━━━━━┯━━━━━━━━━━┯━━━━━━━━━━┑
5 │ Cell 1 │ Cell 2 │ Cell 3 │ Cell 4 │
6 ├──────────┼──────────┼──────────┼──────────┤
7 │ Cell 5 │ Cell 6 │ Cell 7 │ Cell 8 │
8 ┕━━━━━━━━━━┷━━━━━━━━━━┷━━━━━━━━━━┷━━━━━━━━━━┙
9
10 ---
11
12 _Greek:_
13
14 Apò mēkhanês Theós
15
16 ἀπὸ μηχανῆς Θεός
17
18 ---
19
20 _Chinese:_
21
22 bù zuō sǐ jiù bú huì sǐ
23
24 不作死就不会死
25
26 ---
27
28 _Japanese:_
29
30 Saru mo ki kara ochiru
31
32 猿も木から落ちる。
33
34 ---
35
36 _ASCII art:_
37
38 ██████████████
39 ██▓▓▓▓▓▓▓▓▓ M ▓████
40 ██▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓██
41 ██████░░░░██░░██████
42 ██░░░░████░░██░░░░░░░░██
43 ██░░░░████░░░░██░░░░░░██
44 ████░░░░░░██████████
45 ██░░░░░░░░░░░░░██
46 ██░░░░░░░░░██
47 ██░░░░░░██
48 ██▓▓████▓▓▓█
49 ██▓▓▓▓▓▓████▓▓█
50 ██▓▓▓▓▓▓███░░███░
51 ██░░░░░░███████
52 ██░░░░███████
53 ██████████
54 ██▓▓▓▓▓▓▓▓▓██
55 █████████████
56