📄 c.cmd
字号:
ELSE
DO
/* Default is to compile only -- no link, no add to library */
compile = 1
link = 0
addtolib= 0
END
first = 0
IF thisarg \= "" THEN
DO
IF compile = 1 THEN
DO
IF addtolib = 0 THEN CALL CompileToObj thisarg
ELSE CALL CompileToLib thisarg library
END
ELSE
DO
IF addtolib = 1 THEN CALL ArchiveObj thisarg library
END
IF link = 1 THEN CALL LinkProgram thisarg
END
END
endlocal
exit 0
/* End script */
/* Utility subroutines -------------------------------------------------- */
/* CompileToObj <source>
*
* Compile C source file into object file. If this fails, abort the script.
* CCNAME and CCOPTS are REXX variables defined at the top of the script.
*/
CompileToObj:
/* Check to make sure the symbols we require are defined */
/* NOTE: commas at end of line to continue onto next line */
IF (symbol('CCNAME') \= 'VAR') | (symbol('CCOPTS') \= 'VAR') THEN
DO
SAY "One of the required symbols is not defined."
SAY "CCNAME is a " symbol('CCNAME')
SAY "CCOPTS is a " symbol('CCOPTS')
EXIT 99
END
/* Figure out the filename for the source file */
IF (right(ARG(1), 2) = '.c') | (right(ARG(1), 2 ) = '.C') THEN
DO
sourcefile = ARG(1)
basefilename = left(ARG(1), (length(ARG(1)) - 2))
END
ELSE
DO
sourcefile = ARG(1)'.c'
basefilename = ARG(1)
END
/* Join the strings together */
objectfile = basefilename''EOBJ
/* List file name */
listfile = basefilename'.lst'
IF verbose = 1 THEN SAY "Compiling "sourcefile"..."
CCNAME CCOPTS '-c' sourcefile '2>'listfile
IF (RC > 0) THEN
DO
'type 'listfile
exit 2
END
ELSE
DO
'type 'listfile
'del 'listfile' >nul'
END
return
/* ArchiveObj <object> <library> <deleteflag>
*
* Archive the object specified into the library.
* ARCHIVE is a REXX variable defined at the top of the script.
*/
ArchiveObj:
/* Check to make sure the symbols we require are defined */
/* NOTE: commas at end of line to continue onto next line */
IF (symbol('ARCHIVE') \= 'VAR') THEN
DO
SAY "One of the required symbols is not defined."
SAY "ARCHIVE is a " symbol('ARCHIVE')
EXIT 99
END
PARSE ARG object library deleteflag
/* Figure out the filename for the source file */
IF (right(object, 2) = '.c') | (right(object, 2) = '.C') |,
(right(object, OBJLEN) = EOBJ) | (right(object, OBJLEN) = EOBJU) THEN
basefilename = left(object, (length(object) - OBJLEN))
ELSE
basefilename = object
/* Join the strings together to get object filename */
objectfile = basefilename''EOBJ
IF (right(library, LIBLEN) = ELIB) | (right(library, LIBLEN) = ELIBU) THEN
libraryfile = library
ELSE
libraryfile = library''ELIB
IF verbose = 1
THEN SAY "Replacing object "objectfile" in library "libraryfile"..."
ARCHIVE libraryfile objectfile
IF (RC > 0) then exit 3
IF deleteflag = 'delete' THEN
'del 'objectfile' >nul'
return
/* CompileToLib <source> <library>
*
* Compile C source file into object file, then put that object file into
* the library. If either of these steps fail, then abort the script.
*
* CC, CCOPTS, and ARCHIVE are REXX variables defined at the top
* of the script.
*/
CompileToLib:
PARSE ARG SOURCE LIBRARY
CALL CompileToObj SOURCE
IF RC > 0
exit 2
CALL ArchiveObj SOURCE LIBRARY 'delete'
IF RC > 0
exit 3
return
/* LinkProgram <name>
*
* Link the object file name.OBJ to get name.EXE. If the link fails, exit.
*
* CC, CCOPTS and LIBRARIES are REXX variables defined at the top
* of the script.
*/
LinkProgram:
/* Check to make sure the symbols we require are defined */
/* NOTE: commas at end of line to continue onto next one */
IF (symbol('CCNAME') \= 'VAR') | (symbol('CCOPTS') \= 'VAR') |,
(symbol('LIBRARIES') \= 'VAR') THEN
DO
SAY "One of the required symbols is not defined."
EXIT 99
END
basefilename = ARG(1)
IF (right(basefilename, 4) = '.exe') | (right(object, 4) = '.EXE') THEN
basefilename = left(basefilename, (length(basefilename) - 4))
IF (right(basefilename, 2) = '.c') | (right(basefilename, 2) = '.C') THEN
basefilename = left(basefilename, (length(basefilename) - 2))
IF (right(basefilename, OBJLEN) = EOBJ) |,
(right(basefilename, OBJLEN) = EOBJU) THEN
basefilename = left(basefilename, (length(basefilename) - OBJLEN))
/* Join the strings together */
/* If we are linking with -Zexe, then the output filename shouldn't have */
/* ".exe" extension, because this will be added automatically. */
objectfile = basefilename''EOBJ
IF (POS("-Zexe", CCOPTS) > 0) THEN
executable = basefilename
ELSE
executable = basefilename'.exe'
/* Figure out the libraries to link against */
locallibraries = '-L.'
IF symbol('CCLIBS') \= 'VAR' THEN
DO
CALL SysFileTree '*'ELIB, 'files.', 'FO'
DO i = 1 TO files.0
libfilename = FILESPEC('name', files.i)
IF libfilename \= '' THEN
DO
libfilename = STRIP(libfilename) /* CMD.EXE leaves trailing spaces*/
IF (right(libfilename, LIBLEN) = ELIB) |,
(right(libfilename, LIBLEN) = ELIBU) THEN
libraryfile = left(libfilename, (length(libfilename) - LIBLEN))
ELSE
libraryfile = libfilename
locallibraries = locallibraries '-l'libraryfile
END
END
alllibraries = locallibraries' 'LIBRARIES
END
ELSE
DO
alllibraries = CCLIBS
END
IF verbose = 1 THEN SAY "Linking "executable"..."
CCNAME CCOPTS '-o' executable objectfile alllibraries alllibraries
IF (RC > 0) THEN exit 2
return
/* Find a local library to add ourselves into
*
* Strategy is: CCLIBNAME value if set, otherwise look for lib*.a
*/
FindLocalLib:
locallib = value('CCLIBNAME',,'OS2ENVIRONMENT')
IF (locallib = '') THEN
DO
/* Search for a local library to use */
CALL SysFileTree '*'ELIB, 'files.', 'FO'
IF files.0 > 0 THEN
locallib = FILESPEC('name', files.1)
END
IF (locallib = '') THEN locallib = 'libany'ELIB
RETURN locallib
/* Load configuration from file
* Reads in a set of name=value pairs, and skip comments beginning with #
* from the specified file, if the file can be opened. Returns 0 if
* successful, and 1 otherwise.
*/
loadconfig:
configfilename = ARG(1)
if stream(configfilename, 'C', 'QUERY EXISTS') = '' THEN
return 1
DO WHILE LINES(configfilename)
line = LINEIN(configfilename)
IF POS('#', line) == 0 /* Not a comment character */
THEN
DO
PARSE VAR line name '=' setting
IF name \= '' & setting \= '' THEN
DO
/* SAY "Setting: "name"="setting */
dummy = value(name, setting) /* Store name = setting */
END
END
END
RETURN 0
/* End of File */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -