Beispiel #1
0
 void DoTextMaint(ssText t)
 {
     if (t.DoMaint())
     {
         MsgLn("Maintenance done on '" + t.FileName() + "'");
     }
 }
Beispiel #2
0
        public bool DeleteText(ssText dtxt, bool formsToo)
        {
            if (!dtxt.DoubleCheck())
            {
                Err("changed file \"" + dtxt.FileName() + "\"");
                return(false);
            }

            /*/win remove for non-Windowed version
             * if (formsToo) dtxt.DeleteAllForms();
             * // remove for non-Windowed version */
            ssText p = null, t = txts;

            while (t != null && t != dtxt)
            {
                p = t; t = t.Nxt;
            }
            if (t == null)
            {
                return(true);
            }
            if (p == null)
            {
                txts = t.Nxt;
            }
            else
            {
                p.Nxt = t.Nxt;
            }
            //ssTrans.VoidTrans(tlog.Ts, dtxt);
            //ssTrans.VoidTrans(seqRoot.nxt, dtxt);
            prvtxt = txt;
            txt    = null;
            return(true);
        }
Beispiel #3
0
        TList FindText(bool rgx, string pat, bool matching, bool unique)
        {
            TList l  = new TList(null, new ssRange(), null);
            TList lt = l;

            if (pat == null)
            {
                return(new TList(txt, txt.dot, null));
            }
            for (ssText t = txts; t != null; t = t.Nxt)
            {
                bool m = rgx ? Regex.IsMatch(t.MenuLine(), pat, defs.senseCase ? RegexOptions.None : RegexOptions.IgnoreCase) : pat == t.FileName();
                if (matching && m || !matching && !m)
                {
                    lt.nxt = new TList(t, t.dot, null);
                    lt     = lt.nxt;
                }
            }
            if (unique && l.nxt != null && l.nxt.nxt != null)
            {
                throw new ssException("non-unique match for \"" + pat + "\"");
            }
            return(l.nxt);
        }
Beispiel #4
0
        void xCmd(CTree t)
        {
            ssRange levdot = new ssRange();

            if (t == null)
            {
                return;
            }
            ssAddress ad = xAddr(t.ad);
            ssAddress a  = xAddr(t.a);

            if (txt != null)
            {
                levdot = txt.dot;
            }
            if (a != null)
            {
                if (a.txt == null)
                {
                    a.txt = txt;
                }
                else
                {
                    prvtxt = txt;
                    txt    = a.txt;
                }
                txt.dot = a.rng;
            }
            switch (t.cmd)
            {
            case 'p':
                Print();
                break;

            case '=':
                MsgLn(AddressStr());
                break;

            case 'n':
                //MsgLn("working directory '" + Environment.CurrentDirectory + "'");
                for (ssText txt = txts; txt != null; txt = txt.Nxt)
                {
                    MsgLn(txt.MenuLine());
                }
                break;

            case 'a':
                if (swallowing)
                {
                    return;
                }
                txt.dot = txt.dot.To(txt.dot.r);
                if (t.subs != null)
                {
                    Insert(DoSubs("", t.subs));
                }
                else
                {
                    Insert(t.s);
                }
                break;

            case 'i':
                if (swallowing)
                {
                    return;
                }
                txt.dot = txt.dot.To(txt.dot.l);
                if (t.subs != null)
                {
                    Insert(DoSubs("", t.subs));
                }
                else
                {
                    Insert(t.s);
                }
                break;

            case 'c':
                if (swallowing)
                {
                    return;
                }
                if (t.subs != null)
                {
                    Change(DoSubs(txt.ToString(), t.subs));
                }
                else
                {
                    Change(t.s);
                }
                break;

            case 't':
            case 'm':
                MoveCopy(t.cmd, ad);
                break;

            case 'x':
                if (t.sub.nxt.cmd == noCmd)
                {
                    t.sub.nxt.cmd = 'p';
                }
                RegexOptions opts = RegexOptions.Multiline;
                if (!defs.senseCase)
                {
                    opts |= RegexOptions.IgnoreCase;
                }
                MatchCollection ms   = Regex.Matches(txt.ToString(), t.s, opts);
                ssRange         strt = txt.dot;
                foreach (Match m in ms)
                {
                    txt.dot.l   = strt.l + m.Index;
                    txt.dot.len = m.Length;
                    xCmd(t.sub);
                }
                break;

            case 'y':
                if (t.sub.nxt.cmd == noCmd)
                {
                    t.sub.nxt.cmd = 'p';
                }
                opts = RegexOptions.Multiline;
                if (!defs.senseCase)
                {
                    opts |= RegexOptions.IgnoreCase;
                }
                ms   = Regex.Matches(txt.ToString(), t.s, opts);
                strt = txt.dot;
                int l = strt.l;
                foreach (Match m in ms)
                {
                    txt.dot.l = l;
                    txt.dot.r = m.Index + strt.l;
                    xCmd(t.sub);
                    l = strt.l + m.Index + m.Length;
                }
                txt.dot.l = l;
                txt.dot.r = strt.r;
                xCmd(t.sub);
                break;

            case 'X':
            case 'Y':
                t.txts = FindText(true, t.s, t.cmd == 'X', false);
                if (t.txts == null)
                {
                    throw new ssException("file search");
                }
                for (TList tl = t.txts; tl != null; tl = tl.nxt)
                {
                    txt = tl.t;
                    xCmd(t.sub);
                }
                break;

            case 'g':
                opts = RegexOptions.Multiline;
                if (!defs.senseCase)
                {
                    opts |= RegexOptions.IgnoreCase;
                }
                if (Regex.IsMatch(txt.ToString(), t.s, opts))
                {
                    xCmd(t.sub);
                }
                break;

            case 'v':
                opts = RegexOptions.Multiline;
                if (!defs.senseCase)
                {
                    opts |= RegexOptions.IgnoreCase;
                }
                if (!Regex.IsMatch(txt.ToString(), t.s, opts))
                {
                    xCmd(t.sub);
                }
                break;

            case 's':
                opts = RegexOptions.Multiline;
                if (!defs.senseCase)
                {
                    opts |= RegexOptions.IgnoreCase;
                }
                ms   = Regex.Matches(txt.ToString(), t.s, opts);
                strt = txt.dot;
                int cnt = 0;
                foreach (Match m in ms)
                {
                    cnt++;
                    txt.dot.l   = strt.l + m.Index;
                    txt.dot.len = m.Length;
                    if (t.opt == 'g' || cnt == t.n)
                    {
                        if (t.subs != null)
                        {
                            Change(DoSubs(m.ToString(), t.subs));
                        }
                        else
                        {
                            Change(t.rep);
                        }
                    }
                }
                break;

            case 'D':
                TList ts = null;
                if (t.fs == null)
                {
                    if (txt == null)
                    {
                        throw new ssException("no current file");
                    }
                    else
                    {
                        DeleteText(txt, true);
                    }
                }
                else
                {
                    for (SList f = t.fs; f != null; f = f.nxt)
                    {
                        ts = FindText(true, f.s, true, false);
                        if (ts == null)
                        {
                            throw new ssException("warning: no such file '" + f.s + "'");
                        }
                        else
                        {
                            while (ts != null)
                            {
                                DeleteText(ts.t, true);
                                ts = ts.nxt;
                            }
                        }
                    }
                }
                break;

            case 'B':
                if (t.fs != null)
                {
                    AddTexts(SListToArray(t.fs), false);
                }
                else
                {
                    NewText();
                }
                break;

            case 'b':
                bool fnd = false;
                for (SList f = t.fs; f != null; f = f.nxt)
                {
                    ts = FindText(false, f.s, true, true);
                    if (ts != null)
                    {
                        fnd = true; txt = ts.t; break;
                    }
                }
                if (!fnd)
                {
                    throw new ssException("not in menu: \"" + SListJoin(t.fs) + "\"");
                }
                MsgLn(txt.MenuLine());
                WakeUpText(txt);
                break;

            case 'f':
                if (t.fs == null)
                {
                    Msg(txt.MenuLine());
                }
                else
                {
                    Rename(t.fs.s);
                }
                break;

            case 'e':
                if (txt == null)
                {
                    throw new ssException("no current file");
                }
                if (t.fs == null)
                {
                    t.s = txt.Nm;
                }
                else
                {
                    t.s = t.fs.s;
                }
                Encoding enc  = defs.encoding;
                string   fdta = WinRead(t.s, ref enc);
                if (fdta != null)
                {
                    txt.encoding = enc;
                    Rename(t.s);
                    txt.dot.l = 0;
                    txt.dot.r = txt.Length;
                    Change(fdta);
                    txt.dot.To(0);
                    PostEdDot();
                }
                break;

            case 'r':
                if (t.fs == null)
                {
                    t.s = txt.Nm;
                }
                else
                {
                    t.s = t.fs.s;
                }
                enc  = defs.encoding;
                fdta = WinRead(t.s, ref enc);
                if (fdta != null)
                {
                    txt.encoding = enc;
                    Change(fdta);
                    PostEdDot();
                }
                break;

            case 'w':
                if (txt == null)
                {
                    throw new ssException("no current file");
                }
                string s;
                if (t.fs == null)
                {
                    t.s = txt.Nm; s = txt.FileName();
                }
                else
                {
                    t.s = t.fs.s; s = t.fs.s;
                }
                ssRange r = txt.dot;
                if (t.a == null)
                {
                    r.l = 0; r.r = txt.Length;
                }
                string dta = txt.ToString(r.l, r.len);
                string lbl = File.Exists(t.s) ? "" : " (new file) ";
                if (WinWrite(t.s, dta, txt.encoding))
                {
                    if (dta.Length == txt.Length)
                    {
                        txt.TLog.RecordSave();
                    }
                    MsgLn(s + ":" + lbl + "#" + dta.Length.ToString());
                }
                PostEdDot();
                break;

            case 'd':
                Delete();
                break;

            case 'k':
                txt.mark = txt.dot;
                if (a == null)
                {
                    PostEdDot();
                }
                break;

            case 'h':
                ShowHex(txt.ToString());
                break;

            case '!':
                Msg(ShellCmd(t.s, null));
                break;

            case '<':
                Change(ShellCmd(t.s, null));
                break;

            case '>':
                Msg(ShellCmd(t.s, txt.ToString()));
                break;

            case '|':
                Change(ShellCmd(t.s, txt.ToString()));
                break;

            case 'q':
                /*/win Remove for non-windowed version
                 * log.Frm.UpdateDefs();
                 * // */
                defs.SaveDefs(false);
                if (DeleteAllTexts())
                {
                    Environment.Exit(0);
                }
                break;

            case 'Q':
                /*/win Remove for non-windowed version
                 * log.Frm.UpdateDefs();
                 * // */
                defs.SaveDefs(true);
                if (DeleteAllTexts())
                {
                    Environment.Exit(0);
                }
                break;

            case 'H':
                ShowHelp();
                break;

            case 'u':
                Undo(t.n);
                break;

            case '\0':      // end of text
                break;

            case listHead:       // head of sub lists
                break;

            case '{':
                xCmd(t.sub.nxt);      // The head of the sub tree is just another '{', so skip it.
                break;

            case noCmd:
                if (a == null)
                {
                    xNoCmd();
                }
                break;

            case 'T':
                /*/win  remove for non-windowed version
                 * txt.Frm.ChangeTab(t.n);
                 * //  remove for non-windowed version */
                break;

            case 'L':
                /*/win remove for non-windowed version
                *  txt.ChangeEoln(t.s);
                *  //  remove for non-windowed version */
                break;

            case 'F':
                /*/win remove for non-windowed version
                *  txt.FixLineLen(t.n);
                *  //  remove for non-windowed version */
                break;

            case 'C':
                switch (t.opt)
                {
                case 's':
                    defs.senseCase = true;
                    break;

                case 'i':
                    defs.senseCase = false;
                    break;

                default:
                    CultureInfo ci = Thread.CurrentThread.CurrentCulture;
                    TextInfo    ti = ci.TextInfo;
                    s = txt.ToString();
                    switch (t.opt)
                    {
                    case 'u':
                        Change(ti.ToUpper(s));
                        break;

                    case 't':
                        Change(ti.ToTitleCase(s));
                        break;

                    case 'l':
                        Change(ti.ToLower(s));
                        break;
                    }
                    break;
                }
                break;

            case 'E':
                if (txt == null)
                {
                    defs.encoding = decodeEncoding(t.opt);

                    /*/win remove for non-windowing version
                     * log.encoding = defs.encoding;
                     * //   remove for non-windowing version */
                }
                else
                {
                    txt.encoding = decodeEncoding(t.opt);
                }
                break;

            default:
                throw new ssException("unknown command");
            }
            if (a != null)
            {
                PostEdDot();
            }
            if (txt != null && t.nxt != null)
            {
                txt.dot = levdot;
            }
            xCmd(t.nxt);
        }