<commit_before>%%%
%%% Authors:
%%%   <NAME> <<EMAIL>>
%%%   <NAME> <<EMAIL>>
%%%
%%% Copyright:
%%%   <NAME> and <NAME>, 1997-1999
%%%
%%% Last change:
%%%   $Date$ by $Author$
%%%   $Revision$
%%%
%%% This file is part of Mozart, an implementation of Oz 3:
%%%   http://www.mozart-oz.org
%%%
%%% See the file "LICENSE" or
%%%   http://www.mozart-oz.org/LICENSE.html
%%% for information on usage and redistribution
%%% of this file, and for a DISCLAIMER OF ALL WARRANTIES.
%%%

functor
import
   Parser(expandFileName) at 'x-oz://boot/Parser'
   Property(get condGet)
   System(printInfo showError)
   Error(messageToVirtualString)
   OS(tmpnam)
   Open(socket text file)
   Listener('class')
   OPIServer(port)
export
   getOPI:    GetOPI
   condSend:  CondSend
   interface: CompilerInterfaceEmacs
define
   TimeoutToConfigBar = 200
   TimeoutToUpdateBar = TimeoutToConfigBar

   local
      MSG_ERROR = [17]

      class TextSocket from Open.socket Open.text
         prop final
         meth readQuery($) S in
            Open.text, getS(?S)
            case S of false then ""
            elseof [4] then ""   % ^D
            elseof [4 13] then ""   % ^D^M
            else S#'\n'#TextSocket, readQuery($)
            end
         end
      end
   in
      class CompilerInterfaceEmacs from Listener.'class'
         prop final
         attr
            Socket: unit BarSync: _ BarLock: {NewLock} Topped: false
            lastFile: unit lastLine: unit lastColumn: unit
         meth init(CompilerObject Host <= unit Print <= System.printInfo)
            lock Sock Port in
               thread
                  Sock = {New TextSocket server(port: ?Port)}
                  {System.show 'received a connection'}
                  {System.showError 'stderr: received a connection'}
               end
               {Wait Port}
               {Wait OPIServer.port}
               Socket <- Sock
               {Print '\'oz-socket '#case Host of unit then ""
                                     else '"'#Host#'" '
                                     end#Port#' '#OPIServer.port#'\''}
               {System.showInfo ''}
               Listener.'class', init(CompilerObject Serve)
               {System.show 'just telling you I\'m there'}
               {System.showError 'and telling you on stderr too'}
            end
         end
         meth close()
            Listener.'class', close()
            case @Socket of unit then skip
            elseof S then {S close()}
            end
         end
         meth Write(VS)
            case @Socket of unit then skip
            elseof S then
               try
                  {S write(vs: VS)}
               catch system(os(os _ 32 ...) ...) then
                  Socket <- unit
               end
            end<commit_msg>Removed debug messages.<commit_after>%%%
%%% Authors:
%%%   <NAME> <<EMAIL>>
%%%   <NAME> <<EMAIL>>
%%%
%%% Copyright:
%%%   <NAME> and <NAME>, 1997-1999
%%%
%%% Last change:
%%%   $Date$ by $Author$
%%%   $Revision$
%%%
%%% This file is part of Mozart, an implementation of Oz 3:
%%%   http://www.mozart-oz.org
%%%
%%% See the file "LICENSE" or
%%%   http://www.mozart-oz.org/LICENSE.html
%%% for information on usage and redistribution
%%% of this file, and for a DISCLAIMER OF ALL WARRANTIES.
%%%

functor
import
   Parser(expandFileName) at 'x-oz://boot/Parser'
   Property(get condGet)
   System(printInfo showError)
   Error(messageToVirtualString)
   OS(tmpnam)
   Open(socket text file)
   Listener('class')
   OPIServer(port)
export
   getOPI:    GetOPI
   condSend:  CondSend
   interface: CompilerInterfaceEmacs
define
   TimeoutToConfigBar = 200
   TimeoutToUpdateBar = TimeoutToConfigBar

   local
      MSG_ERROR = [17]

      class TextSocket from Open.socket Open.text
         prop final
         meth readQuery($) S in
            Open.text, getS(?S)
            case S of false then ""
            elseof [4] then ""   % ^D
            elseof [4 13] then ""   % ^D^M
            else S#'\n'#TextSocket, readQuery($)
            end
         end
      end
   in
      class CompilerInterfaceEmacs from Listener.'class'
         prop final
         attr
            Socket: unit BarSync: _ BarLock: {NewLock} Topped: false
            lastFile: unit lastLine: unit lastColumn: unit
         meth init(CompilerObject Host <= unit Print <= System.printInfo)
            lock Sock Port in
               thread
                  Sock = {New TextSocket server(port: ?Port)}
               end
               {Wait Port}
               {Wait OPIServer.port}
               Socket <- Sock
               {Print '\'oz-socket '#case Host of unit then ""
                                     else '"'#Host#'" '
                                     end#Port#' '#OPIServer.port#'\''}
               {System.showInfo ''}
               Listener.'class', init(CompilerObject Serve)
            end
         end
         meth close()
            Listener.'class', close()
            case @Socket of unit then skip
            elseof S then {S close()}
            end
         end
         meth Write(VS)
            case @Socket of unit then skip
            elseof S then
               try
                  {S write(vs: VS)}
               catch system(os(os _ 32 ...) ...) then
                  Socket <- unit
               end
            end
{'fraction_non_alphanumeric': 0.11032161555721764, 'fraction_numerical': 0.0074794315632011965, 'mean_word_length': 1.6130923302393747, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6383141', 'n_tokens_mistral': 1585, 'n_tokens_neox': 1481, 'n_words': 455}