Additional debug informations
[vlp.git] / src / int / cint.c
index 00e78b582c250250fd34631e0bfd91e265400bda..300c83ee3827d31aed4aaf29dc59304f7fb8eda8 100644 (file)
@@ -1,5 +1,3 @@
-
 #include "depend.h"
 #include "genint.h"
 #include "int.h"
@@ -13,7 +11,7 @@
 #include <arpa/inet.h>
 #include <errno.h>
 #include <netdb.h>
-#include <qthread.h>
+// #include <qthread.h>
 
 #ifndef NO_PROTOTYPES
 static void load(char *);
@@ -25,7 +23,10 @@ static void initiate();
 int main();
 #endif
 
-
+/**
+ * @file
+ * @brief Compiler and interpreter code
+ */
 
 int internal_sock, graph_sock, net_sock, connected = 0;
 struct sockaddr_un svr;
@@ -37,16 +38,25 @@ int maxDirSet;
 ctx_struct my_ctx;
 ctx_struct parent_ctx;
 
-/* IDs of remote instances */
+/**
+ * IDs of remote instances
+ */
 int RInstance[255];
-/* Direct connection channels */
+
+/**
+ * Direct connection channels
+ */
 int DirConn[255];
 
-/* graphic vars */
+/**
+ * Graphic variables
+ */
 int fcol, bcol, curx=0, cury=0;
 
 
-/* Macro to decode addressing modes : */
+/**
+ * Macro to decode addressing modes:
+ */
 #define getargument(a, argnr)                                       \
     switch (eop->args[ argnr ])                                     \
     {                                                               \
@@ -62,7 +72,12 @@ int fcol, bcol, curx=0, cury=0;
     }
 
 /**
- * Load code and prototypes from file
+ * Loads code and prototypes from files
+ * Files have following extensions:
+ * .ccd - compiler code
+ * .pcd - program code
+ * .trd - traced debug
+ * @param _filename Filename of file to read.
  */
 static void load(char *_filename)
 {
@@ -79,6 +94,7 @@ static void load(char *_filename)
                abend("Memory size too large (use /m option)\n");
 
        addext(filename, ".ccd");
+       fprintf(stderr, "logint: Reading static data from %s file\n", filename);
        if ((fp = fopen(filename, BINARYREAD)) == NULL) {
                fprintf(stderr, "Cannot open .ccd file\n");
                endrun(10);
@@ -95,6 +111,7 @@ static void load(char *_filename)
                ic += n;
                left -= n;
        } while (n != 0);
+       fprintf(stderr, "logint: Static data from %s file has been read\n", filename);
        /* now ic = number of words read */
 
        fclose(fp);
@@ -114,6 +131,7 @@ static void load(char *_filename)
 
        /* Read prototypes from .pcd file */
        addext(filename, ".pcd");
+       fprintf(stderr, "logint: Reading prototypes from %s file\n", filename);
        if ((fp = fopen(filename, BINARYREAD)) == NULL) {
                fprintf(stderr,"Cannot open .pcd file\n");
                endrun(10); 
@@ -128,6 +146,7 @@ static void load(char *_filename)
                        abend("Cannot read .pcd file\n");
        }
        fclose(fp);
+       fprintf(stderr, "logint: Prototypes from: %s file has been read\n", filename);
 
        /* Open trace file */
        if (debug) {
@@ -138,7 +157,14 @@ static void load(char *_filename)
 }
 
 /**
- * Establish configuration parameters
+ * Establishes configuration parameters
+ * Creates two sockets for program run
+ *
+ * @param argc number of passed values in argv array
+ * @param argv[1] 
+ * @param argv[2] 
+ * @param argv[3] if value is equal to: "r", sets global #remote variable to
+ *               TRUE, FALSE otherwise
  */
 static void initiate(int argc, char **argv)
 {
@@ -174,6 +200,7 @@ static void initiate(int argc, char **argv)
        svr.sun_family = AF_UNIX;
        strcpy(svr.sun_path, mynname);
        len = strlen(svr.sun_path) + sizeof(svr.sun_family);
+       fprintf(stderr, "logint: Binding to socket: %s\n", svr.sun_path);
        bind(sock, (struct sockaddr*)&svr, len);
        listen(sock, 5);
 
@@ -190,13 +217,14 @@ static void initiate(int argc, char **argv)
        strcpy(svr.sun_path, argv[1]);
        strcpy(mykname, argv[1]);
        len = strlen(svr.sun_path) + sizeof(svr.sun_family);
+       fprintf(stderr, "logint: Connecting to socket: %s\n", svr.sun_path);
        i = connect(internal_sock, (struct sockaddr*)&svr, len);
 
        if (i==0) {
                fcntl(internal_sock,F_SETFL, O_NONBLOCK |
                                                fcntl(internal_sock,F_GETFL,0));
        }
-       else
+       else {
                while (i!=0) {
                        close(internal_sock);
                        internal_sock = socket(AF_UNIX, SOCK_STREAM, 0);
@@ -204,6 +232,7 @@ static void initiate(int argc, char **argv)
                                        fcntl(internal_sock, F_GETFL, 0));
                        i = connect(internal_sock, (struct sockaddr*)&svr, len);
                }
+       }
        on = 1;
        setsockopt(internal_sock, IPPROTO_TCP, TCP_NODELAY, (char*)&on,
                                                                sizeof(on));
@@ -225,14 +254,19 @@ static void initiate(int argc, char **argv)
        close(sock);
 
        /* load code and prototypes */
-       if (filename != NULL)
+       if (filename != NULL) {
+               fprintf(stderr, "logint: loading code: %s\n", filename);
                load(filename);
-       else
+       }
+       else {
                usage();
+       }
 }
 
-
-void decode(){
+/**
+ *
+ */
+void decode() {
        extopcode *eop;
 
        /* pointer to extended opcode in M */
@@ -246,14 +280,19 @@ void decode(){
        getargument(a3, 2);
 }
 
-/* -------------------------------------------------------------------- */
-
-
+/**
+ * Sends message to graph module.
+ * @param msg Message to send.
+ */
 void send_to_graph(G_MESSAGE *msg)
 {
        write(graph_sock, msg, sizeof(G_MESSAGE));
 }
 
+/**
+ * Reads message from graph module.
+ * @param msg Message to read.
+ */
 int read_from_graph(G_MESSAGE *msg)
 {
        fd_set rset,wset;
@@ -268,9 +307,14 @@ int read_from_graph(G_MESSAGE *msg)
                if (FD_ISSET(graph_sock, &rset))
                        return(read(graph_sock,msg,sizeof(G_MESSAGE)));
        }
-       return(0);
+       return 0;
 }
 
+/**
+ * Reads message from net module.
+ *
+ * @param msg Message to read.
+ */
 int read_from_net(MESSAGE *msg)
 {
        fd_set rset,wset;
@@ -285,11 +329,13 @@ int read_from_net(MESSAGE *msg)
                if (FD_ISSET(net_sock, &rset))
                        return(read(net_sock, msg, sizeof(MESSAGE)));
        }
-       return(0);
+       return 0;
 }
 
 
-/* Get graphic resource number */
+/**
+ * Gets graphic resource number
+ */
 int get_graph_res()
 {
        MESSAGE msg;
@@ -332,7 +378,9 @@ int get_graph_res()
 }
 
 
-/* writeln string */
+/**
+ * Writes string line (ended with new line character)
+ */
 void writeln_str(char *s)
 {
        G_MESSAGE msg;
@@ -346,7 +394,13 @@ void writeln_str(char *s)
        send_to_graph(&msg);
 }
 
-/* write string */
+/**
+ * Writes string
+ *
+ * Passed string is send to graph module by G_MESSAGE packet using send_to_graph
+ *
+ * @param s String to write
+ */
 void write_str(char *s)
 {
        G_MESSAGE msg;
@@ -357,7 +411,13 @@ void write_str(char *s)
        send_to_graph(&msg);
 }
 
-/* write char */
+/**
+ * Writes char
+ *
+ * Passed char is send to graph module by G_MESSAGE packet using send_to_graph
+ *
+ * @param a Character to write
+ */
 void write_char(char a)
 {
        G_MESSAGE msg;
@@ -370,7 +430,10 @@ void write_char(char a)
 }
 
 
-/* read char */
+/**
+ * Reads char
+ * @return Read character
+ */
 char read_char()
 {
        char ch;
@@ -395,7 +458,9 @@ char read_char()
        return ch;
 }
 
-/* read line */
+/**
+ * Reads line
+ */
 void read_line()
 {
        G_MESSAGE msg;
@@ -410,12 +475,15 @@ void read_line()
                st = read_from_graph(&msg);
                if (st > 0)
                        if ((msg.msg_type == MSG_GRAPH) &&
-                               (msg.param.pword[0]== GRAPH_READLN_RESPONSE))
+                               (msg.param.pword[0] == GRAPH_READLN_RESPONSE))
                                break;
        }
 }
 
-/* read string */
+/**
+ * Reads string
+ * @param s Buffer to store string.
+ */
 void read_str(char *s)
 {
        char ss[255];
@@ -430,8 +498,8 @@ void read_str(char *s)
                st = read_from_graph(&msg);
                if (st > 0) {
                        if ((msg.msg_type == MSG_GRAPH) && 
-                               (msg.param.pword[0]==GRAPH_READSTR_RESPONSE)) {
-                               strcpy(ss,msg.param.pstr);
+                               (msg.param.pword[0] == GRAPH_READSTR_RESPONSE)) {
+                               strcpy(ss, msg.param.pstr);
                                break;
                        }
                }
@@ -440,15 +508,18 @@ void read_str(char *s)
 }
 
 /**
- * send message to kernel
+ * Sends message to kernel
+ * @param msg Message to send to kernel
  */
 void send_to_kernel(MESSAGE *msg)
 {
        write(internal_sock, msg, sizeof(MESSAGE));
 }
 
-/* send message to net */
-/* 2010 returns 1 if ok and 0 if node desn't exists */
+/**
+ * Sends message to net
+ * @return Returns 1 if ok and 0 if node desn't exists (since 2010)
+ */
 int send_to_net(MESSAGE *msg)
 {
        int k, len;
@@ -681,8 +752,9 @@ void request_id()
        send_to_graph(&m1);
 }
 
-
-
+/**
+ * Sends MESSAGE
+ */
 void send_ready()
 {
        int sock, len;
@@ -721,16 +793,33 @@ void send_ready()
                                fcntl(DirConn[parent_ctx.node], F_GETFL, 0));
 }
 
+/**
+ *     strcpy(filename, argv[2]);
+ *     strcpy(ProgName, argv[2]);
+ *
+ * @param argv[1] = base name of this interpreter instance.
+ *           For network there is created argv[1].net socket
+ *           For graphics there is created argv[1].gr socket
+ * @param argv[2] = up to 80 characters string (with terminating \0). It is used to
+ *           load selected program
+ * @param argv[3] = if exists and is equal to 'r', this is a remote call
+ */
 int main(int argc, char **argv)
 {
+       fprintf(stderr, "logint: initializing\n");
        /* initialize executor */
        initiate(argc, argv);
        /* initialize running system */
+       fprintf(stderr, "logint: runsys\n");
        runsys();
+       fprintf(stderr, "logint: initializing scheduler\n");
        init_scheduler();
+       fprintf(stderr, "logint: acquiring GRAPH resource\n");
        GraphRes = get_graph_res();
-       if (GraphRes < 0)
+       if (GraphRes < 0) {
+               fprintf(stderr, "logint:  > acquiring GRAPH resource failed\n");
                exit(12);
+       }
 
        request_id();
        if (remote)