File: run_cmd.c

package info (click to toggle)
grpn 1.1.2-3
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 444 kB
  • ctags: 462
  • sloc: ansic: 5,766; sh: 155; makefile: 81
file content (91 lines) | stat: -rw-r--r-- 2,311 bytes parent folder | download | duplicates (3)
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
/*

Copyright (C) 2002  Paul Wilkins

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.

*/
/* run_cmd.c  by Paul Wilkins */

#include <stdio.h>
#include <gtk/gtk.h>

#include "buttons.h"
#include "funcs.h"
#include "editor.h"
#include "error.h"


/* line is the name of the command to run, as stored in
 * the RowInfo struct 
 */
void runCmd(char *line){
   int i, j;
   int cmdLen;
   int lineLen;
   FuncInfo *fi;
   void (*CallBack)(GtkWidget *, gpointer);
   int found = 0;  /* how many matching commands have we found */

   if(*line == '"' || *line == '\'') line++;

   lineLen = strlen(line);

   /* try to find a matching command */
   for(i=0; i<NumFunctionRows; i++){
      for(j=0; j<rowinf[i].numBtns; j++){
         if(rowinf[i].fi[j].cmd != NULL){

            cmdLen = strlen(rowinf[i].fi[j].cmd);

            if(lineLen <= cmdLen){

               if(0 == strncmp(line, rowinf[i].fi[j].cmd, lineLen)){

                  /* store the command */
                  fi = &(rowinf[i].fi[j]);
                  found++;

                  if(lineLen == cmdLen){

                     /* we know this is the command */
                     found = 1;
                     goto MATCH_DONE;
                  }
               }
            }
         }
      }
   }

MATCH_DONE:

   if(found == 1){
      /* doh- we get called recursively is we don't do this */
      cancelEditor();

      /* run the command */
      CallBack = fi->CB;
      CallBack((GtkWidget *)NULL, (gpointer)fi);

   } else if(found > 1){
      sprintf(getStringError(), "%s: Ambigious command name.", line);

   } else {
      sprintf(getStringError(), "%s: Unrecognized command.", line);
   }
}