+ (let* ((linestring (thing-at-point 'line))
+ (rankstring (substring linestring 5 8)))
+
+ (with-current-buffer "List of players"
+ (insert (format " %s " rankstring))))
+
+ (let* ((name (thing-at-point 'word))
+ (linestring (thing-at-point 'line))
+ (namestring (substring linestring 14 47)))
+
+ (with-current-buffer "List of players"
+ (insert (format "%s " namestring))))
+
+ (let* ((linestring (thing-at-point 'line))
+ (elostring (substring linestring 48 52)))
+
+ (with-current-buffer "List of players"
+ (insert (format "%s\n" elostring))))))
+ (with-current-buffer "List of players"
+ (remove-text-properties (point-min)(point-max) '(face nil))))
+
+(defun arbitools-new-trf ()
+ "Create an empty trf file"
+ (interactive)
+ (generate-new-buffer "New trf")
+ (switch-to-buffer "New trf")
+ (set-buffer "New trf")
+ (arbitools-mode)
+ (insert "012 NAME OF THE TOURNAMENT\n")
+ (insert "022 PLACE\n")
+ (insert "032 FEDERATION\n")
+ (insert "042 STARTING DATE (YYYY/MM/DD)\n")
+ (insert "052 ENDING DATE (YYYY/MM/DD)\n")
+ (insert "062 NUMBER OF PLAYERS\n")
+ (insert "072 NUMBER OF RATED PLAYERS\n")
+ (insert "082 NUMBER OF TEAMS\n")
+ (insert "092 TYPE OF TOURNAMENT\n")
+ (insert "102 CHIEF ARBITER\n")
+ (insert "112 DEPUTY CHIEF ARBITER\n")
+ (insert "122 ALLOTED TIMES PER MOVE/GAME\n")
+ (insert "132 DATES YY/MM/DD YY/MM/DD\n")
+ ;; (insert "001 000 GTIT NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN RAT. FED 0000000000 YYYY/MM/DD 00.0 RNK 0000 C R 0000 C R\n")
+ ;; (insert "013 NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN 0000 0000\n")
+)
+
+(defun aribitools-number-of-rounds ()
+ "Get the number of rounds in the tournament"
+ ;; FIXME: EXPERIMENTAL
+ (let ((numberofrounds 0))
+ (save-excursion
+ (beginning-of-buffer)
+ (re-search-forward "^132" nil t)
+ (let* ((linestringrounds (thing-at-point 'line))
+ (actualround " ")
+ (beginning-of-round 91)
+ (end-of-round 99)
+ (continue t))
+
+ (with-current-buffer "Arbitools-output" (insert (format "rounds: %s" linestringrounds)))
+ (with-current-buffer "Arbitools-output" (insert (format "length: %s" (- (length linestringrounds) 4))))
+ ;; For some reason, the length of the string is 4 characters longer than the real line
+ (while continue
+ (if (< end-of-round (length linestringrounds))
+
+ (progn
+ (setq actualround (substring-no-properties linestringrounds beginning-of-round end-of-round))
+ (setq numberofrounds (+ numberofrounds 1))
+ (setq beginning-of-round (+ beginning-of-round 10))
+ (setq end-of-round (+ end-of-round 10)))
+
+ (setq continue nil))))))
+ (numberofrounds))
+
+(defun arbitools-delete-player (player)
+ "Delete a player. Adjust all the rank numbers accordingly."
+ (interactive "splayer: ")
+ (let ((numberofrounds 0)
+ (elo ""))
+
+ (save-excursion
+ (beginning-of-buffer)
+ (re-search-forward "^132" nil t)
+ (let* ((linestringrounds (thing-at-point 'line))
+ (actualround " ")
+ (beginning-of-round 91)
+ (end-of-round 99)
+ (continue t))
+ (while continue
+ (if (< end-of-round (length linestringrounds))
+ (progn
+ (setq actualround (substring-no-properties linestringrounds beginning-of-round end-of-round))
+ (setq numberofrounds (+ numberofrounds 1))
+ (setq beginning-of-round (+ beginning-of-round 10))
+ (setq end-of-round (+ end-of-round 10)))
+ (setq continue nil)))))
+ (save-excursion
+ (beginning-of-buffer)
+ (while (re-search-forward "^001" nil t)
+ (let* ((linestring (thing-at-point 'line))
+ (rankstring (substring linestring 5 8)))
+ (when (= (string-to-number rankstring) (string-to-number player))
+ (forward-char 1)
+ (delete-char 4)
+ (insert " DEL")
+ (setq elo (substring linestring 48 52))
+ (with-current-buffer "Arbitools-output" (insert (format "%s" elo))))
+ (when (> (string-to-number rankstring)(string-to-number player))
+ (forward-char 1)
+ (delete-char 4)
+ (insert-char ?\s (- 4 (length (format "%s" (- (string-to-number rankstring) 1)))))
+ (insert (format "%s" (- (string-to-number rankstring) 1)))
+ (save-excursion
+ (beginning-of-buffer)
+ (while (re-search-forward "^001" nil t)
+ (let* ((linestring2 (thing-at-point 'line))
+ (actualroundopponent (string-to-number (substring linestring2 91 94)))
+ (roundcount 1)
+ (testmessage ""))
+ (forward-char (+ 91 (* (- roundcount 1) 10)))
+ (setq testmessage (thing-at-point 'word))
+ (while (< roundcount numberofrounds)
+ (beginning-of-line)
+ (forward-char (+ 95 (* (- roundcount 1) 10)))
+ (when (string= (format "%s" (string-to-number rankstring)) (thing-at-point 'word))
+ (forward-char -4) ;; go back to the beginning of the opponent's number
+ (delete-char 4) ;; remove the original opponent's number
+ (insert-char ?\s (- 4 (length (format "%s" (- (string-to-number rankstring) 1)))))
+ (insert (format "%s" (- (string-to-number rankstring) 1))))
+ (setq roundcount (+ roundcount 1))))))))))
+ ;;(condition-case nil ;; TODO: fix teams info
+ ;; (while (re-search-forward "^013")
+ ;; (let* ((linestringteam (thing-at-point 'line)))
+ ;; ;; go through team line and read the integrants
+ ;; ;; when integrant equals rankstring rankstring -1
+ ;; ))
+ ;; (error "No teams information"))
+ (save-excursion ;; Actually delete the player's line
+ (beginning-of-buffer)
+ (while (re-search-forward "^001 DEL" nil t)
+ (beginning-of-line)
+ (let ((beg (point)))
+ (forward-line 1)
+ (delete-region beg (point)))))
+ ;; TODO delete the rank from teams section
+ ;; TODO change number of players and number of rated players
+ (save-excursion
+ (with-current-buffer "Arbitools-output" (insert (format "%s" elo)))
+ (beginning-of-buffer)
+ (re-search-forward "^062 ")
+ (let* ((linestring (thing-at-point 'line))
+ (numberofplayers (substring linestring 4)))
+ (delete-char (length numberofplayers))
+ (setq numberofplayers (string-to-number numberofplayers))
+ (setq numberofplayers (- numberofplayers 1))
+ (insert (concat (number-to-string numberofplayers) "\n")))
+ (re-search-forward "^072 ")
+ (let* ((linestring (thing-at-point 'line))
+ (numberofratedplayers (substring linestring 4)))
+ (unless (< (length elo) 2) ;; if elo is 0 or nonexistent
+ (delete-char (length numberofratedplayers))
+ (setq numberofratedplayers (string-to-number numberofratedplayers))
+ (setq numberofratedplayers (- numberofratedplayers 1))
+ (insert (concat (number-to-string numberofratedplayers) "\n")))))))
+
+(defun arbitools-delete-round (round)
+ "Delete a round." ;; FIXME: it breaks when round is the last
+ (interactive "sround: ")
+ (save-excursion
+ (beginning-of-buffer)
+ (while (re-search-forward "^001" nil t)