Exemplo n.º 1
0
void preprocess_mod_file (
    char *filename)         /* The file to read */
{
   
   
   Ifs_Table_t     ifs_table;   /* info read from ifspec.ifs file */
   Status_t        status;      /* Return status */
   const char     *output_filename;
   
   /*
    * Read the entire ifspec.ifs file and load the data into ifs_table
    */
   
   status = read_ifs_file (IFSPEC_FILENAME, GET_IFS_TABLE, &ifs_table);
   
   if (status != OK) {
      exit(1);
   }
   
   current_filename = filename;

   mod_yyin = fopen_cmpp (&current_filename, "r");
   if (mod_yyin == NULL) {
      print_error("ERROR - Could not open input .mod file: %s", current_filename);
      exit(1);
   }
   
   output_filename = change_extension (filename, "c");
   mod_yyout = fopen_cmpp (&output_filename, "w");

   if (mod_yyout == NULL) {
      print_error("ERROR - Could not open output .c file: %s", output_filename);
      exit(1);
   }
   
   mod_ifs_table = &ifs_table;
   mod_num_errors = 0;

   fprintf (mod_yyout, "#line 1 \"%s\"\n", current_filename);
   fprintf (mod_yyout, "#include \"ngspice/cm.h\"\n");
   fprintf (mod_yyout, "extern void %s(Mif_Private_t *);\n",
      ifs_table.name.c_fcn_name);
   fprintf (mod_yyout, "#line 1 \"%s\"\n", current_filename);

   mod_yylineno = 1;

   if (mod_yyparse() || (mod_num_errors > 0)) {
      print_error("Error parsing .mod file: \"%s\"", current_filename);
      unlink (output_filename);
      exit (1);
   }
   fclose (mod_yyout);
   mod_yyrestart(NULL);
}
Exemplo n.º 2
0
static Status_t write_UDNinfo(
    int            num_nodes,  /* Number of node pathnames */
    Node_Info_t    *node_info  /* Info about each node */
)
{
    int         i;                       /* A temporary counter */
    FILE        *fp;   /* File pointer for writing UDNinfo.h */

    const char *filename = "udninfo.h";

    /* Open the file to be written */
    fp = fopen_cmpp(&filename, "w");
    if(fp == NULL) {
        print_error("ERROR - Problems opening %s for write", filename);
        return(ERROR);
    }

    /* Write out the data */
    for(i = 0; i < num_nodes; i++) {
        fprintf(fp, "&udn_%s_info,\n", node_info[i].node_name);
    }

    /* Close the file and return */
    fclose(fp);
    return(OK);
}
Exemplo n.º 3
0
static Status_t write_CMinfo(
    int            num_models,  /* Number of model pathnames */
    Model_Info_t   *model_info  /* Info about each model */
)
{
    int         i;                       /* A temporary counter */
    FILE        *fp;   /* File pointer for writing CMinfo.h */

    const char *filename = "cminfo.h";

    /* Open the file to be written */
    fp = fopen_cmpp(&filename, "w");
    if(fp == NULL) {
        print_error("ERROR - Problems opening %s for write", filename);
        return(ERROR);
    }

    /* Write out the data */
    for(i = 0; i < num_models; i++) {
        fprintf(fp, "&%s_info,\n", model_info[i].cfunc_name);
    }

    /* Close the file and return */
    fclose(fp);
    return(OK);
}
Exemplo n.º 4
0
static Status_t write_objects_inc(
    int            num_models,  /* Number of model pathnames */
    Model_Info_t   *model_info, /* Info about each model */
    int            num_nodes,   /* Number of udn pathnames */
    Node_Info_t    *node_info   /* Info about each node type */
)
{
    int         i;                       /* A temporary counter */
    FILE        *fp;   /* File pointer for writing make_include */

    const char *filename = "objects.inc";

    /* Open the file to be written */
    fp = fopen_cmpp(&filename, "w");
    if(fp == NULL) {
        print_error("ERROR - Problems opening %s for write", filename);
        return(ERROR);
    }

    /* Write out the data */
    for(i = 0; i < num_models; i++) {
        fprintf(fp, "%s/*.o", model_info[i].path_name);
        if((i < (num_models - 1)) || (num_nodes > 0))
            fprintf(fp, " \\\n");
        else
            fprintf(fp, "\n");
    }
    for(i = 0; i < num_nodes; i++) {
        fprintf(fp, "%s/*.o", node_info[i].path_name);
        if(i < (num_nodes - 1))
            fprintf(fp, " \\\n");
        else
            fprintf(fp, "\n");
    }

    /* Close the file and return */
    fclose(fp);
    return(OK);
}
Exemplo n.º 5
0
static Status_t read_udn_type_name(
    const char *path,           /* the path to the node definition file */
    char **node_name            /* the node type name found in the file */
)
{
    FILE        *fp;                    /* file pointer for opened file */
    Boolean_t   found;                  /* true if name found successfully */
    Boolean_t   in_struct;              /* true if found struct with name */
    char        name[MAX_NAME_LEN + 1]; /* temporary storage for name read */
    int         c;                      /* a character read from the file */
    int         i;                      /* a counter */

    static char *struct_type = "Evt_Udn_Info_t";

    /* Open the file from which the node type name will be read */
    fp = fopen_cmpp(&path, "r");
    if(fp == NULL)
        return(ERROR);

    /* Read the file until the definition of the Evt_Udn_Info_t struct */
    /* is found, then get the name of the node type from the first */
    /* member of the structure */
    found = FALSE;
    do {
        /* read the next character */
        c = fgetc(fp);

        /* check for and gobble up comments */
        if(c == '/') {
            c = fgetc(fp);
            if(c == '*') {
                do {
                    c = fgetc(fp);
                    if(c == '*') {
                        c = fgetc(fp);
                        if((c == '/') || (c == EOF))
                            break;
                        else
                            ungetc(c, fp);
                    }
                } while(c != EOF);
            }
        }
        if(c == EOF)
            break;

        /* read until "Evt_Udn_Info_t" is encountered */
        for(i = 0, in_struct = FALSE; ; i++) {
            if(c != struct_type[i])
                break;
            else if(i == (sizeof(struct_type) - 2)) {
                in_struct = TRUE;
                break;
            }
            else
                c = fgetc(fp);
        }
        /* if found it, read until open quote found */
        /* and then read the name until the closing quote is found */
        if(in_struct) {
            do {
                c = fgetc(fp);
                if(c == '"') {
                    i = 0;
                    do {
                        c = fgetc(fp);
                        if(c == '"') {
                            found = TRUE;
                            name[i] = '\0';
                        }
                        else if(c != EOF)
                            name[i++] = (char) c;
                    } while((c != EOF) && (! found));
                }
            } while((c != EOF) && (! found));
        }

    } while((c != EOF) && (! found));

    /* Close the file and return */
    fclose(fp);

    if(found) {
        *node_name = (char *) malloc(strlen(name) + 1);
        strcpy(*node_name, name);
        return(OK);
    }
    else {
        *node_name = NULL;
        return(ERROR);
    }
}
Exemplo n.º 6
0
static Status_t read_udnpath(
    int            *num_nodes,       /* Number of node pathnames found */
    Node_Info_t    **node_info       /* Info about each node */
)
{
    FILE     *fp;                     /* Udn pathname file pointer */
    char     path[MAX_PATH_LEN+2];    /* space to read pathnames into */
    Node_Info_t  *node = NULL;        /* temporary pointer to node info */

    int     n;
    int     i;
    int     j;
    int     len;
    int     line_num;

    const char *filename = UDNPATH_FILENAME;


    /* Initialize number of nodes to zero in case of error */
    *num_nodes = 0;

    /* Open the node pathname file */
    fp = fopen_cmpp(&filename, "r");

    /* For backward compatibility, return with WARNING only if file not found */
    if(fp == NULL) {
        print_error("WARNING - File not found: %s", filename);
        return(OK);
    }

    /* Read the pathnames from the file, one line at a time until EOF */
    n = 0;
    line_num = 0;
    while( fgets(path, sizeof(path), fp) ) {

        line_num++;
        len = (int) strlen(path);

        /* If line was too long for buffer, exit with error */
        if(len > MAX_PATH_LEN) {
            print_error("ERROR - Line %d of %s exceeds %d characters",
                        line_num, filename, MAX_PATH_LEN);
            return(ERROR);
        }

        /* Strip white space including newline */
        for(i = 0, j = 0; i < len; ) {
            if(isspace(path[i])) {
                i++;
            }
            else {
                path[j] = path[i];
                i++;
                j++;
            }
        }
        path[j] = '\0';
        len = j;

        /* Strip trailing '/' if any */
        if(path[len - 1] == '/')
            path[--len] = '\0';

        /* If blank line, continue */
        if(len == 0)
            continue;

        /* Make sure pathname is short enough to add a filename at the end */
        if(len > (MAX_PATH_LEN - (MAX_FN_LEN + 1)) ) {
            print_error("ERROR - Pathname on line %d of %s exceeds %d characters",
                        line_num, filename, (MAX_PATH_LEN - (MAX_FN_LEN + 1)));
            return(ERROR);
        }

        /* Allocate and initialize a new node info structure */
        if(n == 0)
            node = (Node_Info_t *) malloc(sizeof(Node_Info_t));
        else
            node = (Node_Info_t *) realloc(node, (size_t) (n + 1) * sizeof(Node_Info_t));
        node[n].path_name = NULL;
        node[n].node_name = NULL;
        node[n].unique = TRUE;

        /* Put pathname into info structure */
        node[n].path_name = (char *) malloc((size_t) (len+1));
        strcpy(node[n].path_name, path);

        /* Increment count of paths read */
        n++;
    }


    /* Close node pathname file and return data read */
    fclose(fp);

    *num_nodes = n;
    *node_info = node;

    return(OK);

}