├── .projectile ├── img ├── overlay.png ├── overlay2.gif ├── example_1.png ├── example_2.png ├── example_3.png ├── example_4.png ├── example_5.png ├── example_6.png └── example_source.png ├── snippets └── org-mode │ ├── incremental-reading-basic │ └── incremental-reading-cloze ├── README.org ├── incremental-reading.el └── LICENSE /.projectile: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /img/overlay.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vascoferreira25/org-mode-incremental-reading/HEAD/img/overlay.png -------------------------------------------------------------------------------- /img/overlay2.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vascoferreira25/org-mode-incremental-reading/HEAD/img/overlay2.gif -------------------------------------------------------------------------------- /img/example_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vascoferreira25/org-mode-incremental-reading/HEAD/img/example_1.png -------------------------------------------------------------------------------- /img/example_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vascoferreira25/org-mode-incremental-reading/HEAD/img/example_2.png -------------------------------------------------------------------------------- /img/example_3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vascoferreira25/org-mode-incremental-reading/HEAD/img/example_3.png -------------------------------------------------------------------------------- /img/example_4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vascoferreira25/org-mode-incremental-reading/HEAD/img/example_4.png -------------------------------------------------------------------------------- /img/example_5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vascoferreira25/org-mode-incremental-reading/HEAD/img/example_5.png -------------------------------------------------------------------------------- /img/example_6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vascoferreira25/org-mode-incremental-reading/HEAD/img/example_6.png -------------------------------------------------------------------------------- /img/example_source.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vascoferreira25/org-mode-incremental-reading/HEAD/img/example_source.png -------------------------------------------------------------------------------- /snippets/org-mode/incremental-reading-basic: -------------------------------------------------------------------------------- 1 | # -*- mode: snippet -*- 2 | # name: incremental-reading 3 | # key: 4 | ;; Maintainer: Vasco Ferreira 5 | ;; Created: 10 Sep 2021 6 | ;; Version: 0.3 7 | ;; Keywords: anki anki-editor incremental-reading supermemo 8 | ;; Homepage: https://github.com/vascoferreira25/incremental-reading 9 | ;; Package-Requires: ((org) (anki-editor "0.3.3") (request "0.3.0") (emacs "26.6")) 10 | 11 | ;; This file is not part of GNU Emacs. 12 | 13 | 14 | ;;; Commentary: 15 | 16 | ;; Read your notes and create anki cards. Inspired by SuperMemo Incremental 17 | ;; Reading (IR). Your cards stay close to your notes so you don't forget to 18 | ;; updated the cards when you add and update your notes. There is no need to 19 | ;; use a tree structure like anki-editor. 20 | 21 | ;;; Dependencies: 22 | (require 'org) 23 | (require 'ox-html) 24 | (require 'org-protocol) 25 | (require 'anki-editor) 26 | (require 'request) 27 | 28 | 29 | (defgroup incremental-reading nil 30 | "Customizations for incremental-reading." 31 | :group 'org) 32 | 33 | 34 | (defcustom incremental-reading-default-deck 35 | "Default" 36 | "The default deck to be used in the 37 | `incremental-reading-extract-basic' and 38 | `incremental-reading-extract-cloze' functions." 39 | :type '(string)) 40 | 41 | 42 | (defcustom incremental-reading-default-tags 43 | "incremental-reading" 44 | "The default tags to be used in the 45 | `incremental-reading-extract-basic' and 46 | `incremental-reading-extract-cloze' functions." 47 | :type '(string)) 48 | 49 | (defcustom incremental-reading-hide-default-display 50 | ">>>>>>\n" 51 | "The default string displayed when properties are hidden." 52 | :type '(string)) 53 | 54 | (defcustom incremental-reading--basic-template 55 | ":ANKI-CARD: 56 | #+ATTR_DECK: %s 57 | #+ATTR_TYPE: Basic 58 | #+ATTR_TAGS: %s 59 | #+BEGIN_ANKI org 60 | #+ATTR_FIELD: Front 61 | #+BEGIN_FIELD 62 | %s 63 | #+END_FIELD 64 | 65 | #+ATTR_FIELD: Back 66 | #+BEGIN_FIELD 67 | #+END_FIELD 68 | #+END_ANKI 69 | :END: 70 | \n" 71 | "The default template for the basic card extract." 72 | :type '(string)) 73 | 74 | 75 | (defcustom incremental-reading--basic-template-no-back 76 | ":ANKI-CARD: 77 | #+ATTR_DECK: %s 78 | #+ATTR_TYPE: Basic 79 | #+ATTR_TAGS: %s 80 | #+BEGIN_ANKI org 81 | #+ATTR_FIELD: Front 82 | #+BEGIN_FIELD 83 | %s 84 | #+END_FIELD 85 | #+END_ANKI 86 | :END: 87 | \n" 88 | "The default template for the basic card extract without the 89 | back field." 90 | :type '(string)) 91 | 92 | 93 | (defcustom incremental-reading--cloze-template 94 | ":ANKI-CARD: 95 | #+ATTR_DECK: %s 96 | #+ATTR_TYPE: Cloze 97 | #+ATTR_TAGS: %s 98 | #+BEGIN_ANKI org 99 | #+ATTR_FIELD: Text 100 | #+BEGIN_FIELD 101 | %s 102 | #+END_FIELD 103 | 104 | #+ATTR_FIELD: Back Extra 105 | #+BEGIN_FIELD 106 | #+END_FIELD 107 | #+END_ANKI 108 | :END: 109 | \n" 110 | "The default template for the cloze card extract." 111 | :type '(string)) 112 | 113 | 114 | (defcustom incremental-reading--cloze-template-no-back 115 | ":ANKI-CARD: 116 | #+ATTR_DECK: %s 117 | #+ATTR_TYPE: Cloze 118 | #+ATTR_TAGS: %s 119 | #+BEGIN_ANKI org 120 | #+ATTR_FIELD: Text 121 | #+BEGIN_FIELD 122 | %s 123 | #+END_FIELD 124 | #+END_ANKI 125 | :END: 126 | \n" 127 | "The default template for the cloze card extract without the 128 | back field." 129 | :type '(string)) 130 | 131 | 132 | (defun incremental-reading--transform-field-content (content) 133 | "Transform the CONTENT of a field into html." 134 | (let* ((contents-begin (org-element-property :contents-begin content)) 135 | (contents-end (org-element-property :contents-end content))) 136 | (cond 137 | ((cl-equalp 'src-block (org-element-type content)) 138 | (org-html-src-block content nil nil)) 139 | ((and contents-begin contents-end) 140 | (or (org-export-string-as 141 | (buffer-substring-no-properties 142 | contents-begin 143 | contents-end) 144 | anki-editor--ox-anki-html-backend 145 | t 146 | anki-editor--ox-export-ext-plist) 147 | ;; Return empty string because empty fields return nil 148 | "")) 149 | (t "")))) 150 | 151 | 152 | (defun incremental-reading--transform-field (field) 153 | "Transform a special block FIELD to a field in the anki card 154 | and return a list with the field-name and the parsed-contents." 155 | (let* ((field-name (car (org-element-property :attr_field field))) 156 | (field-contents (org-element-contents field)) 157 | (parsed-contents 158 | ;; Transform all the separate paragraphs and elements to a single 159 | ;; string. 160 | (cl-reduce (lambda (a b) (format "%s\n%s" a b)) 161 | (mapcar #'incremental-reading--transform-field-content 162 | field-contents)))) 163 | `(,field-name . ,parsed-contents))) 164 | 165 | 166 | (defun incremental-reading--get-fields (anki-block) 167 | "Return all the fields inside an ANKI-BLOCK." 168 | (org-element-map anki-block 'special-block 169 | (lambda (field) 170 | (when (string= "FIELD" (upcase (org-element-property :type field))) 171 | (incremental-reading--transform-field field))))) 172 | 173 | 174 | (defun incremental-reading/add-note-id (anki-block id) 175 | "Add the card ID to the ANKI-BLOCK." 176 | (save-excursion 177 | (goto-char (org-element-property :begin anki-block)) 178 | (insert (format "#+ATTR_ID: %s\n" id)))) 179 | 180 | 181 | (defun incremental-reading--request-add-card (deck card-type fields tags anki-block) 182 | "Send an http request to the anki-connect addon with DECK, 183 | CARD-TYPE, FIELDS, TAGS and ANKI-BLOCK of the card to add. If it 184 | is successful, update the ANKI-BLOCK id." 185 | (request 186 | "http://127.0.0.1:8765" 187 | :type "POST" 188 | :sync t 189 | :data (json-encode `(("action" . "addNote") 190 | ("version" . 6) 191 | ("params" . (("note" . (("deckName" . ,deck) 192 | ("modelName" . ,card-type) 193 | ("fields" . ,fields) 194 | ("tags" . ,(if tags (split-string tags " ") (list))))))))) 195 | :headers '(("Content-Type" . "application/json")) 196 | :parser 'json-read 197 | :error (cl-function (lambda (&key _ &key error-thrown &allow-other-keys) 198 | (message "Error: %s" (string-trim (cdr error-thrown))))) 199 | :success (cl-function 200 | (lambda (&key response &allow-other-keys) 201 | (message "Added card.") 202 | (incremental-reading/add-note-id 203 | anki-block 204 | (cdr (assoc 'result (request-response-data response)))))))) 205 | 206 | 207 | (defun incremental-reading--request-update-card (id fields tags) 208 | "Send an http request to the anki-connect addon with the ID, 209 | FIELDS and TAGS of the card." 210 | (request 211 | "http://127.0.0.1:8765" 212 | :type "POST" 213 | :sync t 214 | :data (json-encode `(("action" . "updateNoteFields") 215 | ("version" . 6) 216 | ("params" . (("note" . (("id" . ,(string-to-number id)) 217 | ("fields" . ,fields) 218 | ("tags" . ,(if tags (split-string tags " ") (list))))))))) 219 | :headers '(("Content-Type" . "application/json")) 220 | :parser 'json-read 221 | :error (cl-function (lambda (&key _ &key error-thrown &allow-other-keys) 222 | (message "Error: %s" (string-trim (cdr error-thrown))))) 223 | :success (cl-function 224 | (lambda (&key response &allow-other-keys) 225 | (message "Updated card."))))) 226 | 227 | 228 | ;;;###autoload 229 | (defun incremental-reading-parse-cards () 230 | "Parse all the Anki special-blocks in the current buffer and 231 | send them to Anki through http to the anki-connect addon." 232 | (interactive) 233 | ;; Store a reversed list of the special blocks. 234 | ;; This is used to write the ids from bottom to top 235 | (setq anki-blocks (list)) 236 | ;; Parse org-buffer and get all the special-block elements 237 | (org-element-map (org-element-parse-buffer) 'special-block 238 | (lambda (special-block) 239 | ;; If it is a anki block, get the fields of the card 240 | (when (string= "ANKI" (s-upcase (org-element-property :type special-block))) 241 | (setq anki-blocks (cons special-block anki-blocks))))) 242 | ;; Avoid errors when inserting the id by sorting the elements from bottom to 243 | ;; top 244 | (setq anki-blocks (sort (copy-sequence anki-blocks) 245 | (lambda (a b) 246 | (let* ((a-begin (org-element-property :begin a)) 247 | (b-begin (org-element-property :begin b))) 248 | (> a-begin b-begin))))) 249 | ;; Process each anki-block 250 | (mapcar #'incremental-reading-parse-card 251 | anki-blocks)) 252 | 253 | (defun incremental-reading-parse-card (anki-block) 254 | "Parse one card" 255 | (let* ((anki-card-fields (incremental-reading--get-fields anki-block)) 256 | (id (car (org-element-property :attr_id anki-block))) 257 | (deck (car (org-element-property :attr_deck anki-block))) 258 | (card-type (car (org-element-property :attr_type anki-block))) 259 | (tags (car (org-element-property :attr_tags anki-block)))) 260 | (if-let* 261 | ((current-file 262 | (when-let ((f (buffer-file-name))) 263 | (abbreviate-file-name f))) 264 | (field-name 265 | (cond 266 | ((string= card-type "Basic") "Back") 267 | ((string= card-type "Basic (and reversed card)") "Note") 268 | ((string= card-type "Cloze") "Back Extra") 269 | ((string= card-type "Cloze with typed text") "Back Extra") 270 | (t nil))) 271 | (source-string 272 | (format "

Source

" 273 | (url-hexify-string current-file) 274 | (org-html-encode-plain-text current-file))) 275 | (field (assoc field-name anki-card-fields))) 276 | (setf (alist-get field-name anki-card-fields nil nil #'equal) 277 | (concat (cdr field) source-string)) 278 | (nconc anki-card-fields `((,field-name . ,source-string)))) 279 | (if id 280 | (incremental-reading--request-update-card id anki-card-fields tags) 281 | (incremental-reading--request-add-card deck 282 | card-type 283 | anki-card-fields 284 | tags 285 | anki-block)))) 286 | 287 | 288 | (defun incremental-reading--extract-text (selection-start selection-end) 289 | "Extract the substring on region with SELECTION-START and 290 | SELECTION-END and return a substring without properties." 291 | (buffer-substring-no-properties selection-start 292 | selection-end)) 293 | 294 | 295 | (defun incremental-reading-get-tags () 296 | "Get the tags of the current heading." 297 | (message "%S" (org-roam-node-tags (org-roam-node-at-point))) 298 | (concat incremental-reading-default-tags 299 | " " 300 | (if (org-roam-node-at-point) 301 | (mapconcat 'identity 302 | (org-roam-node-tags (org-roam-node-at-point)) " ") 303 | (mapconcat 'identity (split-string (org-get-tags-string) ":" t) " ") 304 | ))) 305 | 306 | 307 | ;;;###autoload 308 | (defun incremental-reading-extract-basic () 309 | "Extract current region into a basic anki card." 310 | (interactive) 311 | (let* ((element (org-element-at-point)) 312 | (selection-start (region-beginning)) 313 | (selection-end (region-end)) 314 | (tags (incremental-reading-get-tags))) 315 | (goto-char (org-element-property :end element)) 316 | (insert (format incremental-reading--basic-template 317 | incremental-reading-default-deck 318 | tags 319 | (incremental-reading--extract-text selection-start 320 | selection-end))))) 321 | 322 | 323 | ;;;###autoload 324 | (defun incremental-reading-extract-basic-no-back () 325 | "Extract current region into a basic anki card without the back 326 | field." 327 | (interactive) 328 | (let* ((element (org-element-at-point)) 329 | (selection-start (region-beginning)) 330 | (selection-end (region-end)) 331 | (tags (incremental-reading-get-tags))) 332 | (goto-char (org-element-property :end element)) 333 | (insert (format incremental-reading--basic-template-no-back 334 | incremental-reading-default-deck 335 | tags 336 | (incremental-reading--extract-text selection-start 337 | selection-end))))) 338 | 339 | 340 | ;;;###autoload 341 | (defun incremental-reading-extract-cloze () 342 | "Extract current region into a cloze anki card." 343 | (interactive) 344 | (let* ((element (org-element-at-point)) 345 | (selection-start (region-beginning)) 346 | (selection-end (region-end)) 347 | (tags (incremental-reading-get-tags))) 348 | (goto-char (org-element-property :end element)) 349 | (insert (format incremental-reading--cloze-template 350 | incremental-reading-default-deck 351 | tags 352 | (incremental-reading--extract-text selection-start 353 | selection-end))))) 354 | 355 | 356 | ;;;###autoload 357 | (defun incremental-reading-extract-cloze-no-back () 358 | "Extract current region into a cloze anki card without the back 359 | field." 360 | (interactive) 361 | (let* ((element (org-element-at-point)) 362 | (selection-start (region-beginning)) 363 | (selection-end (region-end)) 364 | (tags (incremental-reading-get-tags))) 365 | (goto-char (org-element-property :end element)) 366 | (insert (format incremental-reading--cloze-template-no-back 367 | incremental-reading-default-deck 368 | tags 369 | (incremental-reading--extract-text selection-start 370 | selection-end))))) 371 | 372 | ;;;###autoload 373 | (defun incremental-reading-hide-properties () 374 | "Hide all mess properties." 375 | (interactive) 376 | (org-element-map (org-element-parse-buffer) 'special-block 377 | (lambda (special-block) 378 | (when (string= "ANKI" (s-upcase (org-element-property :type special-block))) 379 | (let ((drawer-begin (org-element-property :begin special-block)) 380 | (drawer-end (org-element-property :end special-block)) 381 | (context-bg-eds (list)) 382 | (produce-list (list))) 383 | (org-element-map special-block 'special-block 384 | (lambda (field) 385 | (when (string= "FIELD" (s-upcase (org-element-property :type field))) 386 | ;; Get the each field's context begin and end position list. 387 | ;; Should looks like: '(1 3 8 19), 1 3 is the first field's begin-end, and etc. 388 | (push (org-element-property :contents-begin field) context-bg-eds) 389 | (push (org-element-property :contents-end field) context-bg-eds)))) 390 | (push drawer-end produce-list) 391 | (while context-bg-eds 392 | (push (pop context-bg-eds) produce-list)) 393 | (push drawer-begin produce-list) 394 | (while produce-list 395 | (let ((ol (make-overlay (pop produce-list) (pop produce-list)))) 396 | (overlay-put ol 'display incremental-reading-hide-default-display) 397 | (overlay-put ol 'hidden-anki-prop t))) 398 | (put 'incremental-reading-properties-hide-state 'state 'hidden)))))) 399 | 400 | ;;;###autoload 401 | (defun incremental-reading-show-properties () 402 | "Show all properties." 403 | (interactive) 404 | (remove-overlays 405 | (point-min) (point-max) 'hidden-anki-prop t) 406 | (put 'incremental-reading-properties-hide-state 'state 'shown)) 407 | 408 | ;;;###autoload 409 | (defun incremental-reading-toggle-properties-display () 410 | "Toggle properties hidden/shown state." 411 | (interactive) 412 | (if (eq (get 'incremental-reading-properties-hide-state 'state) 'hidden) 413 | (incremental-reading-show-properties) 414 | (incremental-reading-hide-properties))) 415 | 416 | ;; Create a minor mode to make it easier to load incremental-reading through 417 | ;; hooks. This was sugested by `czqhurricnae'. 418 | ;;;###autoload 419 | (define-minor-mode incremental-reading-mode 420 | "incremental-reading-mode" 421 | :lighter " incremental-reading") 422 | 423 | (provide 'incremental-reading) 424 | 425 | ;;; incremental-reading.el ends here 426 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 2, June 1991 3 | 4 | Copyright (C) 1989, 1991 Free Software Foundation, Inc., 5 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 6 | Everyone is permitted to copy and distribute verbatim copies 7 | of this license document, but changing it is not allowed. 8 | 9 | Preamble 10 | 11 | The licenses for most software are designed to take away your 12 | freedom to share and change it. By contrast, the GNU General Public 13 | License is intended to guarantee your freedom to share and change free 14 | software--to make sure the software is free for all its users. This 15 | General Public License applies to most of the Free Software 16 | Foundation's software and to any other program whose authors commit to 17 | using it. (Some other Free Software Foundation software is covered by 18 | the GNU Lesser General Public License instead.) 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 | this service if you wish), that you receive source code or can get it 25 | if you want it, that you can change the software or use pieces of it 26 | in new free programs; and that you know you can do these things. 27 | 28 | To protect your rights, we need to make restrictions that forbid 29 | anyone to deny you these rights or to ask you to surrender the rights. 30 | These restrictions translate to certain responsibilities for you if you 31 | distribute copies of the software, or if you modify it. 32 | 33 | For example, if you distribute copies of such a program, whether 34 | gratis or for a fee, you must give the recipients all the rights that 35 | you have. You must make sure that they, too, receive or can get the 36 | source code. And you must show them these terms so they know their 37 | rights. 38 | 39 | We protect your rights with two steps: (1) copyright the software, and 40 | (2) offer you this license which gives you legal permission to copy, 41 | distribute and/or modify the software. 42 | 43 | Also, for each author's protection and ours, we want to make certain 44 | that everyone understands that there is no warranty for this free 45 | software. If the software is modified by someone else and passed on, we 46 | want its recipients to know that what they have is not the original, so 47 | that any problems introduced by others will not reflect on the original 48 | authors' reputations. 49 | 50 | Finally, any free program is threatened constantly by software 51 | patents. We wish to avoid the danger that redistributors of a free 52 | program will individually obtain patent licenses, in effect making the 53 | program proprietary. To prevent this, we have made it clear that any 54 | patent must be licensed for everyone's free use or not licensed at all. 55 | 56 | The precise terms and conditions for copying, distribution and 57 | modification follow. 58 | 59 | GNU GENERAL PUBLIC LICENSE 60 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 61 | 62 | 0. This License applies to any program or other work which contains 63 | a notice placed by the copyright holder saying it may be distributed 64 | under the terms of this General Public License. The "Program", below, 65 | refers to any such program or work, and a "work based on the Program" 66 | means either the Program or any derivative work under copyright law: 67 | that is to say, a work containing the Program or a portion of it, 68 | either verbatim or with modifications and/or translated into another 69 | language. (Hereinafter, translation is included without limitation in 70 | the term "modification".) Each licensee is addressed as "you". 71 | 72 | Activities other than copying, distribution and modification are not 73 | covered by this License; they are outside its scope. The act of 74 | running the Program is not restricted, and the output from the Program 75 | is covered only if its contents constitute a work based on the 76 | Program (independent of having been made by running the Program). 77 | Whether that is true depends on what the Program does. 78 | 79 | 1. You may copy and distribute verbatim copies of the Program's 80 | source code as you receive it, in any medium, provided that you 81 | conspicuously and appropriately publish on each copy an appropriate 82 | copyright notice and disclaimer of warranty; keep intact all the 83 | notices that refer to this License and to the absence of any warranty; 84 | and give any other recipients of the Program a copy of this License 85 | along with the Program. 86 | 87 | You may charge a fee for the physical act of transferring a copy, and 88 | you may at your option offer warranty protection in exchange for a fee. 89 | 90 | 2. You may modify your copy or copies of the Program or any portion 91 | of it, thus forming a work based on the Program, and copy and 92 | distribute such modifications or work under the terms of Section 1 93 | above, provided that you also meet all of these conditions: 94 | 95 | a) You must cause the modified files to carry prominent notices 96 | stating that you changed the files and the date of any change. 97 | 98 | b) You must cause any work that you distribute or publish, that in 99 | whole or in part contains or is derived from the Program or any 100 | part thereof, to be licensed as a whole at no charge to all third 101 | parties under the terms of this License. 102 | 103 | c) If the modified program normally reads commands interactively 104 | when run, you must cause it, when started running for such 105 | interactive use in the most ordinary way, to print or display an 106 | announcement including an appropriate copyright notice and a 107 | notice that there is no warranty (or else, saying that you provide 108 | a warranty) and that users may redistribute the program under 109 | these conditions, and telling the user how to view a copy of this 110 | License. (Exception: if the Program itself is interactive but 111 | does not normally print such an announcement, your work based on 112 | the Program is not required to print an announcement.) 113 | 114 | These requirements apply to the modified work as a whole. If 115 | identifiable sections of that work are not derived from the Program, 116 | and can be reasonably considered independent and separate works in 117 | themselves, then this License, and its terms, do not apply to those 118 | sections when you distribute them as separate works. But when you 119 | distribute the same sections as part of a whole which is a work based 120 | on the Program, the distribution of the whole must be on the terms of 121 | this License, whose permissions for other licensees extend to the 122 | entire whole, and thus to each and every part regardless of who wrote it. 123 | 124 | Thus, it is not the intent of this section to claim rights or contest 125 | your rights to work written entirely by you; rather, the intent is to 126 | exercise the right to control the distribution of derivative or 127 | collective works based on the Program. 128 | 129 | In addition, mere aggregation of another work not based on the Program 130 | with the Program (or with a work based on the Program) on a volume of 131 | a storage or distribution medium does not bring the other work under 132 | the scope of this License. 133 | 134 | 3. You may copy and distribute the Program (or a work based on it, 135 | under Section 2) in object code or executable form under the terms of 136 | Sections 1 and 2 above provided that you also do one of the following: 137 | 138 | a) Accompany it with the complete corresponding machine-readable 139 | source code, which must be distributed under the terms of Sections 140 | 1 and 2 above on a medium customarily used for software interchange; or, 141 | 142 | b) Accompany it with a written offer, valid for at least three 143 | years, to give any third party, for a charge no more than your 144 | cost of physically performing source distribution, a complete 145 | machine-readable copy of the corresponding source code, to be 146 | distributed under the terms of Sections 1 and 2 above on a medium 147 | customarily used for software interchange; or, 148 | 149 | c) Accompany it with the information you received as to the offer 150 | to distribute corresponding source code. (This alternative is 151 | allowed only for noncommercial distribution and only if you 152 | received the program in object code or executable form with such 153 | an offer, in accord with Subsection b above.) 154 | 155 | The source code for a work means the preferred form of the work for 156 | making modifications to it. For an executable work, complete source 157 | code means all the source code for all modules it contains, plus any 158 | associated interface definition files, plus the scripts used to 159 | control compilation and installation of the executable. However, as a 160 | special exception, the source code distributed need not include 161 | anything that is normally distributed (in either source or binary 162 | form) with the major components (compiler, kernel, and so on) of the 163 | operating system on which the executable runs, unless that component 164 | itself accompanies the executable. 165 | 166 | If distribution of executable or object code is made by offering 167 | access to copy from a designated place, then offering equivalent 168 | access to copy the source code from the same place counts as 169 | distribution of the source code, even though third parties are not 170 | compelled to copy the source along with the object code. 171 | 172 | 4. You may not copy, modify, sublicense, or distribute the Program 173 | except as expressly provided under this License. Any attempt 174 | otherwise to copy, modify, sublicense or distribute the Program is 175 | void, and will automatically terminate your rights under this License. 176 | However, parties who have received copies, or rights, from you under 177 | this License will not have their licenses terminated so long as such 178 | parties remain in full compliance. 179 | 180 | 5. You are not required to accept this License, since you have not 181 | signed it. However, nothing else grants you permission to modify or 182 | distribute the Program or its derivative works. These actions are 183 | prohibited by law if you do not accept this License. Therefore, by 184 | modifying or distributing the Program (or any work based on the 185 | Program), you indicate your acceptance of this License to do so, and 186 | all its terms and conditions for copying, distributing or modifying 187 | the Program or works based on it. 188 | 189 | 6. Each time you redistribute the Program (or any work based on the 190 | Program), the recipient automatically receives a license from the 191 | original licensor to copy, distribute or modify the Program subject to 192 | these terms and conditions. You may not impose any further 193 | restrictions on the recipients' exercise of the rights granted herein. 194 | You are not responsible for enforcing compliance by third parties to 195 | this License. 196 | 197 | 7. If, as a consequence of a court judgment or allegation of patent 198 | infringement or for any other reason (not limited to patent issues), 199 | conditions are imposed on you (whether by court order, agreement or 200 | otherwise) that contradict the conditions of this License, they do not 201 | excuse you from the conditions of this License. If you cannot 202 | distribute so as to satisfy simultaneously your obligations under this 203 | License and any other pertinent obligations, then as a consequence you 204 | may not distribute the Program at all. For example, if a patent 205 | license would not permit royalty-free redistribution of the Program by 206 | all those who receive copies directly or indirectly through you, then 207 | the only way you could satisfy both it and this License would be to 208 | refrain entirely from distribution of the Program. 209 | 210 | If any portion of this section is held invalid or unenforceable under 211 | any particular circumstance, the balance of the section is intended to 212 | apply and the section as a whole is intended to apply in other 213 | circumstances. 214 | 215 | It is not the purpose of this section to induce you to infringe any 216 | patents or other property right claims or to contest validity of any 217 | such claims; this section has the sole purpose of protecting the 218 | integrity of the free software distribution system, which is 219 | implemented by public license practices. Many people have made 220 | generous contributions to the wide range of software distributed 221 | through that system in reliance on consistent application of that 222 | system; it is up to the author/donor to decide if he or she is willing 223 | to distribute software through any other system and a licensee cannot 224 | impose that choice. 225 | 226 | This section is intended to make thoroughly clear what is believed to 227 | be a consequence of the rest of this License. 228 | 229 | 8. If the distribution and/or use of the Program is restricted in 230 | certain countries either by patents or by copyrighted interfaces, the 231 | original copyright holder who places the Program under this License 232 | may add an explicit geographical distribution limitation excluding 233 | those countries, so that distribution is permitted only in or among 234 | countries not thus excluded. In such case, this License incorporates 235 | the limitation as if written in the body of this License. 236 | 237 | 9. The Free Software Foundation may publish revised and/or new versions 238 | of the General Public License from time to time. Such new versions will 239 | be similar in spirit to the present version, but may differ in detail to 240 | address new problems or concerns. 241 | 242 | Each version is given a distinguishing version number. If the Program 243 | specifies a version number of this License which applies to it and "any 244 | later version", you have the option of following the terms and conditions 245 | either of that version or of any later version published by the Free 246 | Software Foundation. If the Program does not specify a version number of 247 | this License, you may choose any version ever published by the Free Software 248 | Foundation. 249 | 250 | 10. If you wish to incorporate parts of the Program into other free 251 | programs whose distribution conditions are different, write to the author 252 | to ask for permission. For software which is copyrighted by the Free 253 | Software Foundation, write to the Free Software Foundation; we sometimes 254 | make exceptions for this. Our decision will be guided by the two goals 255 | of preserving the free status of all derivatives of our free software and 256 | of promoting the sharing and reuse of software generally. 257 | 258 | NO WARRANTY 259 | 260 | 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY 261 | FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN 262 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES 263 | PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED 264 | OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 265 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS 266 | TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE 267 | PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, 268 | REPAIR OR CORRECTION. 269 | 270 | 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 271 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR 272 | REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, 273 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING 274 | OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED 275 | TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY 276 | YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER 277 | PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE 278 | POSSIBILITY OF SUCH DAMAGES. 279 | 280 | END OF TERMS AND CONDITIONS 281 | 282 | How to Apply These Terms to Your New Programs 283 | 284 | If you develop a new program, and you want it to be of the greatest 285 | possible use to the public, the best way to achieve this is to make it 286 | free software which everyone can redistribute and change under these terms. 287 | 288 | To do so, attach the following notices to the program. It is safest 289 | to attach them to the start of each source file to most effectively 290 | convey the exclusion of warranty; and each file should have at least 291 | the "copyright" line and a pointer to where the full notice is found. 292 | 293 | 294 | Copyright (C) 295 | 296 | This program is free software; you can redistribute it and/or modify 297 | it under the terms of the GNU General Public License as published by 298 | the Free Software Foundation; either version 2 of the License, or 299 | (at your option) any later version. 300 | 301 | This program is distributed in the hope that it will be useful, 302 | but WITHOUT ANY WARRANTY; without even the implied warranty of 303 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 304 | GNU General Public License for more details. 305 | 306 | You should have received a copy of the GNU General Public License along 307 | with this program; if not, write to the Free Software Foundation, Inc., 308 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 309 | 310 | Also add information on how to contact you by electronic and paper mail. 311 | 312 | If the program is interactive, make it output a short notice like this 313 | when it starts in an interactive mode: 314 | 315 | Gnomovision version 69, Copyright (C) year name of author 316 | Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 317 | This is free software, and you are welcome to redistribute it 318 | under certain conditions; type `show c' for details. 319 | 320 | The hypothetical commands `show w' and `show c' should show the appropriate 321 | parts of the General Public License. Of course, the commands you use may 322 | be called something other than `show w' and `show c'; they could even be 323 | mouse-clicks or menu items--whatever suits your program. 324 | 325 | You should also get your employer (if you work as a programmer) or your 326 | school, if any, to sign a "copyright disclaimer" for the program, if 327 | necessary. Here is a sample; alter the names: 328 | 329 | Yoyodyne, Inc., hereby disclaims all copyright interest in the program 330 | `Gnomovision' (which makes passes at compilers) written by James Hacker. 331 | 332 | , 1 April 1989 333 | Ty Coon, President of Vice 334 | 335 | This General Public License does not permit incorporating your program into 336 | proprietary programs. If your program is a subroutine library, you may 337 | consider it more useful to permit linking proprietary applications with the 338 | library. If this is what you want to do, use the GNU Lesser General 339 | Public License instead of this License. 340 | --------------------------------------------------------------------------------