This file is indexed.

/usr/lib/ruby/1.9.1/diakonos.rb is in diakonos 0.9.0-1.

This file is owned by root:root, with mode 0o755.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
#! /usr/bin/ruby1.9.1

# == Diakonos
#
# A Linux console text editor for the masses.
# :title: Diakonos
#
# Author:: Pistos (irc.freenode.net)
# http://diakonos.pist0s.ca/
# Copyright (c) 2004-2011 Pistos
#
# This software is released under the MIT licence.
# See the LICENCE file included with this program, or
# http://www.opensource.org/licenses/mit-license.php
#
require 'curses'
require 'open3'
require 'thread'
require 'English'
require 'set'
require 'yaml'
require 'digest/md5'
require 'timeout'

require 'diakonos/core-ext/object'
require 'diakonos/core-ext/enumerable'
require 'diakonos/core-ext/regexp'
require 'diakonos/core-ext/hash'
require 'diakonos/core-ext/string'
require 'diakonos/core-ext/fixnum'
require 'diakonos/core-ext/bignum'
require 'diakonos/buffer-hash'
require 'diakonos/sized-array'

require 'diakonos/version'
require 'diakonos/installation'

require 'diakonos/about'
require 'diakonos/buffer-management'
require 'diakonos/config'
require 'diakonos/cursor'
require 'diakonos/functions'
require 'diakonos/functions/basics'
require 'diakonos/functions/bookmarking'
require 'diakonos/functions/buffers'
require 'diakonos/functions/clipboard'
require 'diakonos/functions/cursor'
require 'diakonos/functions/grepping'
require 'diakonos/functions/indentation'
require 'diakonos/functions/readline'
require 'diakonos/functions/search'
require 'diakonos/functions/selection'
require 'diakonos/functions/sessions'
require 'diakonos/functions/shell'
require 'diakonos/functions/tags'
require 'diakonos/functions/text-manipulation'
require 'diakonos/functions-deprecated'
require 'diakonos/help'
require 'diakonos/display'
require 'diakonos/display/format'
require 'diakonos/grep'
require 'diakonos/hooks'
require 'diakonos/interaction'
require 'diakonos/keying'
require 'diakonos/logging'
require 'diakonos/list'
require 'diakonos/search'
require 'diakonos/sessions'

require 'diakonos/text-mark'
require 'diakonos/bookmark'
require 'diakonos/ctag'
require 'diakonos/finding'
require 'diakonos/buffer'
require 'diakonos/buffer/bookmarking'
require 'diakonos/buffer/cursor'
require 'diakonos/buffer/delete'
require 'diakonos/buffer/display'
require 'diakonos/buffer/indentation'
require 'diakonos/buffer/file'
require 'diakonos/buffer/searching'
require 'diakonos/buffer/selection'
require 'diakonos/buffer/undo'
require 'diakonos/clipboard'
require 'diakonos/clipboard-klipper'
require 'diakonos/clipboard-klipper-dbus'
require 'diakonos/clipboard-xclip'
require 'diakonos/extension'
require 'diakonos/extension-set'
require 'diakonos/key-map'
require 'diakonos/mode'
require 'diakonos/readline'
require 'diakonos/readline/functions'

require 'diakonos/vendor/fuzzy_file_finder'


module Diakonos

  DONT_ADJUST_ROW       = false
  ADJUST_ROW            = true
  PROMPT_OVERWRITE      = true
  DONT_PROMPT_OVERWRITE = false
  QUIET                 = true
  NOISY                 = false
  AFTER_CHAR            = true
  ON_CHAR               = false
  INCLUSIVE             = true
  NOT_INCLUSIVE         = false

  DEFAULT_TAB_SIZE = 8

  FORCE_REVERT = true
  ASK_REVERT   = false

  ASK_REPLACEMENT = true
  NO_REPLACEMENT  = nil

  CASE_SENSITIVE   = true
  CASE_INSENSITIVE = false

  LANG_TEXT = 'text'

  class Diakonos

    attr_reader :diakonos_home, :script_dir, :clipboard,
      :list_filename, :hooks, :indenters, :indenters_next_line, :unindenters, :closers,
      :functions_last, :there_was_non_movement, :do_display, :testing, :buffers

    include ::Diakonos::Functions

    def initialize( argv = [] )
      @diakonos_home = File.expand_path( ( ENV[ 'HOME' ] || '' ) + '/.diakonos' )
      mkdir @diakonos_home
      @script_dir = "#{@diakonos_home}/scripts"
      mkdir @script_dir
      @extensions = ExtensionSet.new( File.join( @diakonos_home, 'extensions' ) )
      initialize_session

      @files = Array.new
      @read_only_files = Array.new
      @config_filename = nil
      parse_options argv

      init_help

      @debug          = File.new( File.join( @diakonos_home, 'debug.log' ), 'w' )
      @list_filename  = File.join( @diakonos_home, 'listing.txt' )
      @diff_filename  = File.join( @diakonos_home, 'text.diff' )
      @help_filename  = File.join( @help_dir, 'about-help.dhf' )
      @error_filename = File.join( @diakonos_home, 'diakonos.err' )
      @about_filename = File.join( @diakonos_home, 'about.dhf' )

      @win_main         = nil
      @win_context      = nil
      @win_status       = nil
      @win_interaction  = nil
      @win_line_numbers = nil
      @buffers          = Array.new

      load_configuration

      @quitting         = false

      @x = 0
      @y = 0

      @buffer_stack           = Array.new
      @buffer_current         = nil

      @cursor_stack           = Array.new
      @cursor_stack_pointer   = nil

      @bookmarks              = Hash.new

      @macro_history          = nil
      @macro_input_history    = nil
      @macros                 = Hash.new
      @functions_last         = SizedArray.new(2)
      @playing_macro          = false

      @display_mutex          = Mutex.new
      @display_queue_mutex    = Mutex.new
      @display_queue          = nil
      @do_display             = true
      @iline_mutex            = Mutex.new

      @tag_stack              = Array.new
      @last_search_regexps    = nil
      @iterated_choice        = nil
      @choice_iterations      = 0
      @there_was_non_movement = false
      @status_vars            = Hash.new

      # Readline histories
      @rlh_general  = Array.new
      @rlh_files    = Array.new
      @rlh_search   = Array.new
      @rlh_shell    = Array.new
      @rlh_help     = Array.new
      @rlh_sessions = Array.new

      @hooks = {
        :after_buffer_switch => [],
        :after_open          => [],
        :after_save          => [],
        :after_startup       => [],
      }
    end

    def mkdir( dir )
      if ! FileTest.exists?( dir )
        Dir.mkdir dir
      end
    end

    def parse_options( argv )
      @post_load_script = ""
      while argv.length > 0
        arg = argv.shift
        case arg
        when '-c', '--config'
          @config_filename = argv.shift
          if @config_filename.nil?
            print_usage
            exit 1
          end
        when '-e', '--execute'
          post_load_script = argv.shift
          if post_load_script.nil?
            print_usage
            exit 1
          else
            @post_load_script << "\n#{post_load_script}"
          end
        when '-h', '--help'
          print_usage
          exit 1
        when '-m', '--open-matching'
          regexp = argv.shift
          files = `egrep -rl '#{regexp}' *`.split( /\n/ )
          if files.any?
            @files.concat( files.map { |f| session_file_hash_for f } )
            script = "\nfind '#{regexp}', case_sensitive: true"
            @post_load_script << script
          end
        when '-ro'
          filename = argv.shift
          if filename.nil?
            print_usage
            exit 1
          else
            h = session_file_hash_for( filename )
            h[ 'read_only' ] = true
            @read_only_files.push h
          end
        when '-s', '--load-session'
          @session_to_load = session_filepath_for( argv.shift )
        when '--test', '--testing'
          @testing = true
        when '--uninstall'
          puts "use Debian installer to uninstall Diakonos"
          #uninstall
        when '--uninstall-without-confirmation'
          puts "use Debian installer to uninstall Diakonos"
          #uninstall false
        when '--version'
          puts "Diakonos #{::Diakonos::VERSION} (#{::Diakonos::LAST_MODIFIED})"
          exit 0
        else
          # a name of a file to open
          @files.push session_file_hash_for( arg )
        end
      end
    end

    def print_usage
      puts "Usage: #{$0} [options] [file] [file...]"
      puts "\t--help\tDisplay usage"
      puts "\t-c <config file>\tLoad this config file instead of ~/.diakonos/diakonos.conf"
      puts "\t-e, --execute <Ruby code>\tExecute Ruby code (such as Diakonos commands) after startup"
      puts "\t-m, --open-matching <regular expression>\tOpen all matching files under current directory"
      puts "\t-ro <file>\tLoad file as read-only"
      puts "\t-s, --load-session <session identifier>\tLoad a session"
      #puts "\t--uninstall[-without-confirmation]\tUninstall Diakonos"
    end

    def clear_non_movement_flag
      @there_was_non_movement = false
    end

    # -----------------------------------------------------------------------

    def start
      require 'diakonos/window'

      initialize_display

      @files.each do |file|
        @buffers << Buffer.new( file )
      end
      @files = []
      @read_only_files.each do |file|
        @buffers << Buffer.new( file )
      end
      if ! @testing
        session_buffers = session_startup
      end
      session_buffer_number = @session[ 'buffer_current' ] || 1
      @files.each do |file_info|
        @buffers << Buffer.new( file_info )
      end
      if @buffers.empty?
        @buffers << Buffer.new
      end

      @buffers.each do |buffer|
        buffer.reset_display
      end

      if ENV[ 'COLORTERM' ] == 'gnome-terminal'
        help_key = 'Shift-F1'
      else
        help_key = 'F1'
      end
      set_iline "Diakonos #{VERSION} (#{LAST_MODIFIED})   #{help_key} for help  F12 to configure  Ctrl-Q to quit"

      scripts = @extensions.scripts + Dir[ "#{@script_dir}/*" ]
      scripts.each do |script|
        begin
          require script
        rescue Exception => e
          show_exception(
            e,
            [
              "There is a syntax error in the script.",
              "An invalid hook name was used."
            ]
          )
        end
      end

      @hooks.each do |hook_name, hook|
        hook.sort { |a,b| a[ :priority ] <=> b[ :priority ] }
      end

      if session_buffers
        session_buffers.each do |buffer|
          close_buffer buffer
        end
      end

      if @post_load_script
        eval @post_load_script
      end

      run_hook_procs :after_startup
      if ! switch_to_buffer_number( session_buffer_number )
        debug_log "Failed to switch to buffer #{session_buffer_number.inspect}"
        switch_to_buffer_number 1
      end

      @buffers.each do |b|
        run_hook_procs :after_open, b
        b.cursor_to( b.last_row, b.last_col, Buffer::DONT_DISPLAY )
      end
      buffer_current.cursor_to( buffer_current.last_row, buffer_current.last_col, Buffer::DONT_DISPLAY )

      if @config_problems.any?
        File.open( @error_filename, "w" ) do |f|
          f.puts "There are #{@config_problems.size} problems with the configuration file(s):"
          @config_problems.each do |p|
            f.puts p
          end
        end
        open_file @error_filename
      end

      if ! @testing && ! @settings[ 'suppress_welcome' ]
        open_file "#{@help_dir}/welcome.dhf"
      else
        conflict_regexp_source = '^<{4,}'
        if seek(conflict_regexp_source)
          find conflict_regexp_source
        end
      end

      begin
        # Main keyboard loop.
        while ! @quitting
          process_keystroke
          @win_main.refresh
        end
      rescue SignalException => e
        debug_log "Terminated by signal (#{e.message})"
      end

      cleanup_display
      cleanup_session

      @debug.close
    end

    def uninstall( confirm = true )
      #inst = ::Diakonos::INSTALL_SETTINGS[ :installed ]

      #if confirm
      #  puts inst[ :files ].sort.join( "\n" )
      #  puts
      #  puts inst[ :dirs ].sort.map { |d| "#{d}/" }.join( "\n" )
      #  puts
      #  puts "The above files will be removed.  The above directories will be removed if they are empty.  Proceed?  (y/n)"
      #  answer = $stdin.gets
      #  case answer
      #  when /^y/i
      #    puts "Deleting..."
      #  else
      #    puts "Uninstallation aborted."
      #    exit 1
      #  end
      #end

      #require 'fileutils'
      #inst[ :files ].each do |f|
      #  FileUtils.rm f
      #end
      #inst[ :dirs ].sort { |d1,d2| d2.length <=> d1.length }.each do |d|
      #  begin
      #    FileUtils.rmdir d
      #  rescue Errno::ENOTEMPTY
      #  end
      #  if File.exists? d
      #    $stderr.puts "(#{d} not removed)"
      #  end
      #end

      #exit 0
    end

    def get_language_from_name( name )
      @filemasks.each do |language,filemask|
        if name =~ filemask
          return language
        end
      end
      nil
    end

    def get_language_from_shabang( first_line )
      @bangmasks.each do |language,bangmask|
        if first_line =~ bangmask
          return language
        end
      end
      nil
    end

    def show_exception( e, probable_causes = [ "Unknown" ] )
      begin
        File.open( @error_filename, "w" ) do |f|
          f.puts "Diakonos Error:"
          f.puts
          f.puts "#{e.class}: #{e.message}"
          f.puts
          f.puts "Probable Causes:"
          f.puts
          probable_causes.each do |pc|
            f.puts "- #{pc}"
          end
          f.puts
          f.puts "----------------------------------------------------"
          f.puts "If you can reproduce this error, please report it at"
          f.puts "https://github.com/Pistos/diakonos/issues !"
          f.puts "----------------------------------------------------"
          f.puts e.backtrace
        end
        open_file @error_filename
      rescue Exception => e2
        debug_log "EXCEPTION: #{e.message}"
        debug_log "\t#{e.backtrace}"
      end
    end

    def start_recording_macro( name = nil )
      return if @macro_history
      @macro_name = name
      @macro_history = Array.new
      @macro_input_history = Array.new
      set_iline "Started macro recording."
    end

    def stop_recording_macro
      @macro_history.pop  # Remove the stop_recording_macro command itself
      @macros[ @macro_name ] = [ @macro_history, @macro_input_history ]
      @macro_history = nil
      @macro_input_history = nil
      set_iline "Stopped macro recording."
    end

    def load_tags
      @tags = Hash.new
      if buffer_current && buffer_current.name
        path = File.expand_path( File.dirname( buffer_current.name ) )
        tagfile = path + "/tags"
      else
        tagfile = "./tags"
      end

      if ! FileTest.exists? tagfile
        set_iline "(tags file not found)"
      else
        IO.foreach( tagfile ) do |line_|
          line = line_.chomp
          # <tagname>\t<filepath>\t<line number or regexp>\t<kind of tag>
          tag, file, command, kind, rest = line.split( /\t/ )
          command.gsub!( /;"$/, "" )
          if command =~ /^\/.*\/$/
            command = command[ 1...-1 ]
          end
          @tags[ tag ] ||= Array.new
          @tags[ tag ].push CTag.new( file, command, kind, rest )
        end
      end
    end

    def escape_quotes( str )
      temp = ''
      str.each_byte do |b|
        if b == 39
          temp << 39
          temp << 92
          temp << 39
        end
        temp << b
      end
      temp
    end

    # @return [Array] the filename and line number parsed
    def parse_filename_and_line_number( s )
      if(
        # Ruby
        s =~ /from (.+):(\d+)/ ||
        # Python
        s =~ /File "(.+)", line (\d+)/ ||
        # Perl
        s =~ /at (.+) line (\d+)/ ||
        # generic
        s =~ /^(.+):(\d+)/
      )
        [ $1, ( $2.to_i - 1 ) ]
      else
        [ s, nil ]
      end
    end

  end

end

::Diakonos.check_ruby_version

if __FILE__ == $PROGRAM_NAME
  $diakonos = Diakonos::Diakonos.new( ARGV )
  $diakonos.start
end