⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mknobjs.c

📁 basic.c */ /**//* Project:NeuroBasic, basic package*//**/ /* Survey:This is a simple Basic b-code
💻 C
字号:
/****************************************************************//*								*//* Name:	mknobjs.c					*//*								*//* Project:	NeuroBasic, utility program			*//*								*//* Survey:	Creates a header file containing all neuro-	*//*		object definitions of the input files and one	*//*		union structure of them all (neuro_obj_t).	*//*		Output is the last argument, inputs are all	*//*		other arguments.				*//*								*//* Author:	Urs Mueller					*//*		Electronics Laboratory, ETH Zuerich		*//*		Switzerland					*//*								*//* Created:	July 20, 1994					*//* Modified:	August 28, 1994 (um)				*//*								*//****************************************************************/#include <stdio.h>#include <string.h>#include <stdlib.h>#include <ctype.h>/* macros *//**********/#define LIST_MAX		512#define LINE_MAX		64#define OBJECT_MAX		40#define STR_BUF_MAX		256#define TRUE			1#define FALSE			0/* global variables *//********************/int	error_flag;char	object_list[LIST_MAX][LINE_MAX];long	nobjects;char	str_buf[STR_BUF_MAX];static char *str_upper(char *str)/*=============================*/{  char		*s;    for (s = str; *s != 0; s++)    *s = toupper(*s);  return str;} /* end of str_upper() */static int getput(FILE *ifpt, FILE *ofpt)/*=====================================*/{  char		ch;  ch = fgetc(ifpt);  if (ch != EOF) fputc(ch, ofpt);  return ch;} /* end of getput() */static void scan_header(char *filename, FILE *ofpt1, FILE *ofpt2)/*=============================================================*//* Look for neuro-object types and copy "filename" to "ofpt1".   Furthermore, look for constants and write constant table   into "ofpt2".*/{  FILE		*ifpt;  char		ch, *ps1, *ps2, *ps3;  long		i;  ifpt = fopen(filename, "r");  if (ifpt == NULL)  {    printf("ERROR of mknobjs: cannot read header file \"%s\".\n",	   filename);    error_flag = EXIT_FAILURE;    return;  }  ch = getput(ifpt, ofpt1);  while (ch != EOF)  {    if (nobjects >= LIST_MAX)    {      printf("ERROR of mknobjs: too many neuro-objects.\n");      error_flag = EXIT_FAILURE;      break;    }    while (ch != EOF && ch != '}') ch = getput(ifpt, ofpt1);    for (ch = getput(ifpt, ofpt1);	 ch != EOF && isspace(ch);	 ch = getput(ifpt, ofpt1));    for (i = 0; ch != ';'	 && i < LINE_MAX-1;	 i++, ch = getput(ifpt, ofpt1))      object_list[nobjects][i] = ch;    object_list[nobjects][i] = 0;    if (object_list[nobjects][i-2] == '_'	&& object_list[nobjects][i-1] == 't')    {      object_list[nobjects][i-2] = 0;		/* cut "_t" */      nobjects++;    }  }  fclose(ifpt);  /*===== get constants =====*/  ifpt = fopen(filename, "r");  while (!feof(ifpt))  {    fgets(str_buf, STR_BUF_MAX, ifpt);    if (strncmp("#define", str_buf, 7) == 0)    {      for (ps1 = str_buf + 7; isspace(*ps1); ps1++);      for (ps2 = ps1; *ps2 != 0 && !isspace(*ps2); ps2++);      if (*ps2 != 0) *ps2++ = 0;      while (isspace(*ps2)) ps2++;      for (ps3 = ps2; *ps3 != 0 && !isspace(*ps3); ps3++);      if (*ps3 != 0) *ps3++ = 0;      fprintf(ofpt2, "  {\"%s\", %s},\n", ps1, ps2);    }  }  fclose(ifpt);} /* end of scan_header() */static void write_file_header(FILE *fpt)/*====================================*/{  fprintf(fpt, "/*\n");  fprintf(fpt, "   This file was created by mknobjs. ");  fprintf(fpt, "Do not modify it!\n");  fprintf(fpt, "*/\n\n\n");} /* end of write_file_header() */int main(int argc, char *argv[])/******************************/{  int		arg;  long		obj;  FILE		*ofpt1, *ofpt2;  char		name[FILENAME_MAX], *pc;    if (argc < 4)  {    printf("Usage: mknobjs <input1> <input2> ... <.c-output> ");    printf("<.h-output>.\n");    return EXIT_FAILURE;  }  ofpt1 = fopen(argv[argc-1], "w");  if (ofpt1 == NULL)  {    printf("ERROR of mknobjs: cannot open output file \"%s\".\n",	   argv[argc-1]);    return EXIT_FAILURE;  }  ofpt2 = fopen(argv[argc-2], "w");  if (ofpt2 == NULL)  {    printf("ERROR of mknobjs: cannot open output file \"%s\".\n",	   argv[argc-2]);    fclose(ofpt1);    return EXIT_FAILURE;  }  error_flag = EXIT_SUCCESS;  pc = strrchr(argv[argc-1], '/');  if (pc == NULL) pc = strrchr(argv[argc-1], '\\');  if (pc == NULL) pc = argv[argc-1]; else pc++;  strcpy(name, pc);  pc = strrchr(name, '.');  if (pc != NULL) *pc = 0;  str_upper(name);  write_file_header(ofpt1);  fprintf(ofpt1, "\n\n#ifndef __%s__\n#define __%s__\n\n\n",	  name, name);  fprintf(ofpt1, "#include <musiclib.h>\n");  fprintf(ofpt1, "#include <mdisk.h>\n\n\n");  write_file_header(ofpt2);  fprintf(ofpt2, "#include <stdio.h>\n");  fprintf(ofpt2, "#include <m_host.h>\n");  fprintf(ofpt2, "#include \"basic.h\"\n\n\n");  fprintf(ofpt2, "bconst_t bconst[] =\n{\n");  for (arg = 1; arg < argc-2; arg++)  {    scan_header(argv[arg], ofpt1, ofpt2);  }  fprintf(ofpt2, "  {NULL, 0}\n};\n");  fprintf(ofpt1, "typedef struct\n{\n");  fprintf(ofpt1, "  MINT filler[%d];\n", OBJECT_MAX);  fprintf(ofpt1, "  MINT obtype;\n");  fprintf(ofpt1, "  size_t trans_buf_size;\n");  fprintf(ofpt1, "  void (*fn_release)(MINT nobj);\n");  fprintf(ofpt1, "  MINT (*fn_load)(MINT nobj);\n");  fprintf(ofpt1, "  MINT (*fn_save)(MINT nobj);\n");  fprintf(ofpt1, "  MINT (*fn_nput)(MINT nobj, MINT nx, MINT ny,");  fprintf(ofpt1, " MFLOAT value);\n");  fprintf(ofpt1,	  "  MFLOAT (*fn_nget)(MINT nobj, MINT nx, MINT ny);\n");  fprintf(ofpt1, "  MINT (*fn_rand)(MINT nobj, MFLOAT range);\n");  fprintf(ofpt1, "} public_t;\n\n\n");  fprintf(ofpt1, "/* Neuro-Object Type */\n");  fprintf(ofpt1, "/*********************/\n\n");  fprintf(ofpt1, "typedef union\n{\n");  for (obj = 0; obj < nobjects; obj++)    fprintf(ofpt1, "  %s_t %s;\n", object_list[obj], object_list[obj]);  fprintf(ofpt1, "  public_t public;\n");  fprintf(ofpt1, "} neuro_obj_t;\n\n");  fprintf(ofpt1, "typedef enum\n{\n");  fprintf(ofpt1, "  N_FREE,\n");  fprintf(ofpt1, "  N_INIT");  for (obj = 0; obj < nobjects; obj++)    fprintf(ofpt1, ",\n  N_%s", str_upper(object_list[obj]));  fprintf(ofpt1, "\n} obtype_t;\n");  fprintf(ofpt1, "\n\n#endif /* __%s__ */\n", name);  if (ferror(ofpt1))  {    printf("ERROR of mknobjs: Write error on \"%s\".\n", argv[argc-1]);    error_flag = EXIT_FAILURE;  }  fclose(ofpt1);  if (ferror(ofpt2))  {    printf("ERROR of mknobjs: Write error on \"%s\".\n", argv[argc-2]);    error_flag = EXIT_FAILURE;  }  fclose(ofpt2);  return error_flag;} /* end of main() */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -