Annotation of Gnu-Mach/mig/header.c, revision 1.1

1.1     ! root        1: /* 
        !             2:  * Mach Operating System
        !             3:  * Copyright (c) 1991,1990 Carnegie Mellon University
        !             4:  * All Rights Reserved.
        !             5:  * 
        !             6:  * Permission to use, copy, modify and distribute this software and its
        !             7:  * documentation is hereby granted, provided that both the copyright
        !             8:  * notice and this permission notice appear in all copies of the
        !             9:  * software, derivative works or modified versions, and any portions
        !            10:  * thereof, and that both notices appear in supporting documentation.
        !            11:  * 
        !            12:  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS 
        !            13:  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
        !            14:  * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
        !            15:  * 
        !            16:  * Carnegie Mellon requests users of this software to return to
        !            17:  * 
        !            18:  *  Software Distribution Coordinator  or  [email protected]
        !            19:  *  School of Computer Science
        !            20:  *  Carnegie Mellon University
        !            21:  *  Pittsburgh PA 15213-3890
        !            22:  * 
        !            23:  * any improvements or extensions that they make and grant Carnegie the
        !            24:  * rights to redistribute these changes.
        !            25:  */
        !            26: 
        !            27: #include "write.h"
        !            28: #include "utils.h"
        !            29: #include "global.h"
        !            30: #include "error.h"
        !            31: 
        !            32: static void
        !            33: WriteIncludes(FILE *file)
        !            34: {
        !            35:     fprintf(file, "#include <mach/kern_return.h>\n");
        !            36:     fprintf(file, "#include <mach/port.h>\n");
        !            37:     fprintf(file, "#include <mach/message.h>\n");
        !            38:     fprintf(file, "\n");
        !            39: }
        !            40: 
        !            41: static void
        !            42: WriteDefines(FILE *file)
        !            43: {
        !            44: }
        !            45: 
        !            46: static void
        !            47: WriteMigExternal(FILE *file)
        !            48: {
        !            49:     fprintf(file, "#ifdef\tmig_external\n");
        !            50:     fprintf(file, "mig_external\n");
        !            51:     fprintf(file, "#else\n");
        !            52:     fprintf(file, "extern\n");
        !            53:     fprintf(file, "#endif\n");
        !            54: }
        !            55: 
        !            56: static void
        !            57: WriteProlog(FILE *file, const char *protect)
        !            58: {
        !            59:     if (protect != strNULL) {
        !            60:        fprintf(file, "#ifndef\t_%s\n", protect);
        !            61:        fprintf(file, "#define\t_%s\n", protect);
        !            62:        fprintf(file, "\n");
        !            63:     }
        !            64: 
        !            65:     fprintf(file, "/* Module %s */\n", SubsystemName);
        !            66:     fprintf(file, "\n");
        !            67: 
        !            68:     WriteIncludes(file);
        !            69:     WriteDefines(file);
        !            70: }
        !            71: 
        !            72: static void
        !            73: WriteEpilog(FILE *file, const char *protect)
        !            74: {
        !            75:     if (protect != strNULL) {
        !            76:        fprintf(file, "\n");
        !            77:        fprintf(file, "#endif\t/* not defined(_%s) */\n", protect);
        !            78:     }
        !            79: }
        !            80: 
        !            81: static void
        !            82: WriteUserRoutine(FILE *file, const routine_t *rt)
        !            83: {
        !            84:     fprintf(file, "\n");
        !            85:     fprintf(file, "/* %s %s */\n", rtRoutineKindToStr(rt->rtKind), rt->rtName);
        !            86:     WriteMigExternal(file);
        !            87:     fprintf(file, "%s %s\n", ReturnTypeStr(rt), rt->rtUserName);
        !            88:     fprintf(file, "#if\t%s\n", LintLib);
        !            89:     fprintf(file, "    (");
        !            90:     WriteList(file, rt->rtArgs, WriteNameDecl, akbUserArg, ", " , "");
        !            91:     fprintf(file, ")\n");
        !            92:     WriteList(file, rt->rtArgs, WriteUserVarDecl, akbUserArg, ";\n", ";\n");
        !            93:     fprintf(file, "{ ");
        !            94:     if (!rt->rtProcedure)
        !            95:        fprintf(file, "return ");
        !            96:     fprintf(file, "%s(", rt->rtUserName);
        !            97:     WriteList(file, rt->rtArgs, WriteNameDecl, akbUserArg, ", ", "");
        !            98:     fprintf(file, "); }\n");
        !            99:     fprintf(file, "#else\n");
        !           100:     fprintf(file, "(\n");
        !           101:     WriteList(file, rt->rtArgs, WriteUserVarDecl, akbUserArg, ",\n", "\n");
        !           102:     fprintf(file, ");\n");
        !           103:     fprintf(file, "#endif\n");
        !           104: }
        !           105: 
        !           106: void
        !           107: WriteUserHeader(FILE *file, const statement_t *stats)
        !           108: {
        !           109:     register const statement_t *stat;
        !           110:     const char *protect = strconcat(SubsystemName, "_user_");
        !           111: 
        !           112:     WriteProlog(file, protect);
        !           113:     for (stat = stats; stat != stNULL; stat = stat->stNext)
        !           114:        switch (stat->stKind)
        !           115:        {
        !           116:          case skRoutine:
        !           117:            WriteUserRoutine(file, stat->stRoutine);
        !           118:            break;
        !           119:          case skImport:
        !           120:          case skUImport:
        !           121:            WriteImport(file, stat->stFileName);
        !           122:            break;
        !           123:          case skSImport:
        !           124:            break;
        !           125:          default:
        !           126:            fatal("WriteHeader(): bad statement_kind_t (%d)",
        !           127:                  (int) stat->stKind);
        !           128:        }
        !           129:     WriteEpilog(file, protect);
        !           130: }
        !           131: 
        !           132: static void
        !           133: WriteServerRoutine(FILE *file, const routine_t *rt)
        !           134: {
        !           135:     fprintf(file, "\n");
        !           136:     fprintf(file, "/* %s %s */\n", rtRoutineKindToStr(rt->rtKind), rt->rtName);
        !           137:     WriteMigExternal(file);
        !           138:     fprintf(file, "%s %s\n", ReturnTypeStr(rt), rt->rtServerName);
        !           139:     fprintf(file, "#if\t%s\n", LintLib);
        !           140:     fprintf(file, "    (");
        !           141:     WriteList(file, rt->rtArgs, WriteNameDecl, akbServerArg, ", " , "");
        !           142:     fprintf(file, ")\n");
        !           143:     WriteList(file, rt->rtArgs, WriteServerVarDecl,
        !           144:              akbServerArg, ";\n", ";\n");
        !           145:     fprintf(file, "{ ");
        !           146:     if (!rt->rtProcedure)
        !           147:        fprintf(file, "return ");
        !           148:     fprintf(file, "%s(", rt->rtServerName);
        !           149:     WriteList(file, rt->rtArgs, WriteNameDecl, akbServerArg, ", ", "");
        !           150:     fprintf(file, "); }\n");
        !           151:     fprintf(file, "#else\n");
        !           152:     fprintf(file, "(\n");
        !           153:     WriteList(file, rt->rtArgs, WriteServerVarDecl,
        !           154:              akbServerArg, ",\n", "\n");
        !           155:     fprintf(file, ");\n");
        !           156:     fprintf(file, "#endif\n");
        !           157: }
        !           158: 
        !           159: void
        !           160: WriteServerHeader(FILE *file, const statement_t *stats)
        !           161: {
        !           162:     register const statement_t *stat;
        !           163:     const char *protect = strconcat(SubsystemName, "_server_");
        !           164: 
        !           165:     WriteProlog(file, protect);
        !           166:     for (stat = stats; stat != stNULL; stat = stat->stNext)
        !           167:        switch (stat->stKind)
        !           168:        {
        !           169:          case skRoutine:
        !           170:            WriteServerRoutine(file, stat->stRoutine);
        !           171:            break;
        !           172:          case skImport:
        !           173:          case skSImport:
        !           174:            WriteImport(file, stat->stFileName);
        !           175:            break;
        !           176:          case skUImport:
        !           177:            break;
        !           178:          default:
        !           179:            fatal("WriteServerHeader(): bad statement_kind_t (%d)",
        !           180:                  (int) stat->stKind);
        !           181:        }
        !           182:     WriteEpilog(file, protect);
        !           183: }
        !           184: 
        !           185: static void
        !           186: WriteInternalRedefine(FILE *file, register const routine_t *rt)
        !           187: {
        !           188:     fprintf(file, "#define %s %s_external\n", rt->rtUserName, rt->rtUserName);
        !           189: }
        !           190: 
        !           191: void
        !           192: WriteInternalHeader(FILE *file, const statement_t *stats)
        !           193: {
        !           194:     register const statement_t *stat;
        !           195: 
        !           196:     for (stat = stats; stat != stNULL; stat = stat->stNext)
        !           197:        switch (stat->stKind)
        !           198:        {
        !           199:          case skRoutine:
        !           200:            WriteInternalRedefine(file, stat->stRoutine);
        !           201:            break;
        !           202:          case skImport:
        !           203:          case skUImport:
        !           204:          case skSImport:
        !           205:            break;
        !           206:          default:
        !           207:            fatal("WriteInternalHeader(): bad statement_kind_t (%d)",
        !           208:                  (int) stat->stKind);
        !           209:        }
        !           210: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.