home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / smapp100.zip / sm10.zip / smg.c < prev    next >
C/C++ Source or Header  |  2000-05-14  |  44KB  |  1,200 lines

  1. /* ------------------------------------------------------------------------
  2.  *
  3.  *        File: smg.c
  4.  *     Project: Source Mapper.
  5.  *     Created: April 7, 1992.
  6.  * Description: This is the main source module of the project, which 
  7.  *              defines the main() function.
  8.  *
  9.  * Copyright (C) 2000 Leif-Erik Larsen.
  10.  * This file is part of the Source Mapper source package.
  11.  * Source Mapper is free software; you can redistribute it and/or modify
  12.  * it under the terms of the GNU General Public License as published
  13.  * by the Free Software Foundation, in version 2 as it comes in the
  14.  * "COPYING" file of the XWorkplace main distribution.
  15.  * This program is distributed in the hope that it will be useful,
  16.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  18.  * GNU General Public License for more details.
  19.  *
  20.  * ------------------------------------------------------------------------ */
  21.  
  22.  
  23.  
  24.  
  25. #include "smg.h"
  26.  
  27.  
  28.  
  29.  
  30. char progdir[MAXPATH];          /* Path to EXE-file of program        */
  31. ErrorType Error;
  32. int _iErrNo;                    /* Shadow of errno value */
  33.  
  34.  
  35.  
  36.  
  37. struct
  38. {
  39.    int iCod;
  40.    char* pMsg;
  41. }
  42.    ErrMsg[] =
  43. {
  44.    {  0, "Unknown error, or no error at all!" },
  45.    {  1, "No matching file(s)!" },
  46.    {  2, "Failed on open project file!" },
  47.    {  3, "Failed on write to file!" },
  48.    {  4, "Failed on create project file!" },
  49.    {  5, "A rare error due to a bug in the program. Please write down the\n"
  50.          "below information and a short description of what caused this\n"
  51.          "error (if possible). Then contact the author to get help!" },
  52.    {  6, "Can't fetch time stamp, or file not found!" },
  53.    {  7, "Conflicting options: Can't link map without making .smo-files!" },
  54.    {  8, "Unknown generate method!" },
  55.    {  9, "Failed on create temporary file:" },
  56.    { 10, "To many arguments from system! (Try to use an option file.)" },
  57.    { 11, "Failed on open temporary file!" },
  58.    { 12, "Failed on sort contents of file!" },
  59.    { 13, "Seek error!" },
  60.    { 14, "Out of memory! (Try to split source into smaller modules.)" },
  61.    { 15, "Failed on read file!" },
  62.    { 16, "Failed on open file!" },
  63.    { 17, "Unknown or illegal argument of option! (Using default)" },
  64.    { 18, "Only one sourcefile can be specified if some has wildcard(s)!" },
  65.    { 19, "Unknown option or switch!" },
  66.    { 20, "To long line in sourcefile! Max length of a line is" },
  67.    { 21, "To many {-block-} levels in sourcefile (max is 15)" },
  68.    { 22, "Failed on create final map file" },
  69.    { 23, "Failed on open sourcefile" },
  70.    { 24, "Failed on open options file" },
  71.    { 25, "Illegal level of block. Probably due to a syntax error." },
  72.    { 26, "Failed on copy filebytes to" },
  73.    { 27, "Function name is to long. Max length is" },
  74.    { 28, "Identifier name is to long. Max length is" },
  75. };
  76.  
  77.  
  78.  
  79.  
  80. char *ptbl[PT_MAXNR] =  /* Parametertabell (Parameter TaBLe) */
  81. {
  82.    /* ______ Totalinfo: ______ */
  83.    "iti",    /* PT_iti: Inkluder */
  84.    "clt",    /* PT_ctl: Antall linjer */
  85.    "cel",    /* PT_cel: Antall tomme linjer */
  86.    "coc",    /* PT_coc: Antall linjer med bare komentar */
  87.    "clc",    /* PT_clc: Antall linjer med kode */
  88.    "cfu",    /* PT_cfu: Antall funksjoner */
  89.    "cco",    /* PT_cco: Antall komentarblokker */
  90.  
  91.    /* ______ Funksjonsregister: ______ */
  92.    "ifr",    /* PT_ifr: Inkluder */
  93.    "fso",    /* PT_fso: Sorteringsmetode (1=Navn, 2=Linjenummer) */
  94.  
  95.    /* ______ Liste over funksjonskall: ______ */
  96.    "ilf",    /* PT_ilf: Inkluder */
  97.    "slf",    /* PT_slf: Selektiv liste */
  98.    "fln",    /* PT_fln: Stigende linjenummer-referanser */
  99.  
  100.    /* ______ Liste over identifikatorer: ______ */
  101.    "iil",    /* PT_iil: Inkluder */
  102.    "sli",    /* PT_sli: Selektiv liste */
  103.    "iln",    /* PT_iln: Stigende linjenummer-referanser */
  104.  
  105.    /* ______ Kall-sekvenser: ______ */
  106.    "csi",    /* PT_csi: Include */
  107.    "cie",    /* PT_cie: Include external functions */
  108.    "csg",    /* PT_csg: Use graphicals characters */
  109.    "csf",    /* PT_csf: Format (1=List, 2=Flowchart) */
  110.    "cwi",    /* PT_cwi: Width of indents */
  111.    "cir",    /* PT_cir: Include indexregister */
  112.    "cdt",    /* PT_cdt: Default top level function */
  113.  
  114.    /* ______ Linjeinformasjon: ______ */
  115.    "ili",    /* PT_ili: Inkluder */
  116.    "lll",    /* PT_lll: Lokale linjenummer */
  117.    "rbi",    /* PT_rbi: Blokknivå */
  118.    "lcl",    /* PT_lcl: Anngi rene komentarlinjer */
  119.  
  120.    /* ______ Informasjon om funksjoner: ______ */
  121.    "lfi",    /* PT_lfi: Inkluder funksjonsinfo */
  122.    "LLF",    /* PT_LLF: Antall linjer i funksjon */
  123.    "LEF",    /* PT_LEF: Antall tomme linjer i funksjon */
  124.    "LCF",    /* PT_LCF: Antall komentarlinjer i funksjon */
  125.    "LCO",    /* PT_LCO: Antall kodelinjer i funksjon */
  126.    "LCC",    /* PT_LCC: Antall komentarblokker i funksjon */
  127.    "LLC",    /* PT_LLC: Liste over kallere av funksjonen */
  128.  
  129.    /* ______ Diverse: ______ */
  130.    "NPs",    /* PT_NPs: Streng for sideskift */
  131.    "NPS",    /* PT_NPS: Sideskift ved streng for sideskift */
  132.    "NFU",    /* PT_NFU: Sideskift ved funksjonstart */
  133.    "NFI",    /* PT_NFI: Sideskift mellom kart seksjoner */
  134.    "cse",    /* PT_cse: Kolonneseparator (1=Tab, 2=Mellomrom) */
  135.    "dtu",    /* PT_dtu: Slett mellomfiler (.smg-filer) etter bruk */
  136.    "gcb",    /* PT_gcb: Generer komentarblokker */
  137.    "tab",    /* PT_tab: Tabulatorbredde */
  138.    "dis",    /* PT_dis: Display information on screen during processing */
  139.  
  140.    /* ______ Generer: ______ */
  141.    "gen",    /* PT_gen: Generer (1=Alt, 2=Mellom, 3=Alt) */
  142.    "met",    /* PT_met: Metode (1=Link, 2=Make, 3=Build) */
  143.    "pof",    /* PT_pof: Katalog til mellomfiler */
  144.    "pmf",    /* PT_pmf: Katalog til kartfiler */
  145.    "ptf",    /* PT_ptf: Katalog til midlertidige filer */
  146.    "upf",    /* PT_upf: Bruk prosjektfil */
  147.  
  148.    /* ______ Brytere som bare utf¢res direkte, uten å lagres i valg-fil: */
  149.    "uof",    /* PT_uof: Bruk valgfil */
  150.    "wof",    /* PT_wof: Lagre valgfil */
  151.    "res",    /* PT_res: Reset valg. Valg settes tilbake til standard */
  152.    "hlp",    /* PT_hlp: Gir bruker hjelp om oppgitt bryter */
  153. };
  154.  
  155.  
  156.  
  157.  
  158. char *defoptcom[PT_MAXNR] = /* DEFault OPTion COMments */
  159. {
  160.    /* ______ Totalinfo: ______ */
  161.    "Include header with total information",                     /* PT_iti */
  162.    "Count total number of lines in source",                     /* PT_ctl */
  163.    "Count number of empty lines in source",                     /* PT_cel */
  164.    "Count number of comment lines in source",                   /* PT_coc */
  165.    "Count number of lines containing code in source",           /* PT_clc */
  166.    "Count number of functions in source",                       /* PT_cfu */
  167.    "Count number of comment blocks in source",                  /* PT_cco */
  168.  
  169.    /* ______ Funksjonsregister: ______ */
  170.    "Include register of functions in source",                   /* PT_ifr */
  171.    "Sorting method of functions register (1=Name, 2=Linr)",     /* PT_fso */
  172.  
  173.    /* ______ Liste over funksjonskall: ______ */
  174.    "Include list of function calls in source",                  /* PT_ilf */
  175.    "Selective list of functions in list of functioncalls",      /* PT_slf */
  176.    "Rising line numbers references in list of function calls",  /* PT_fln */
  177.  
  178.    /* ______ Liste over identifikatorer: ______ */
  179.    "Include list of identifiers in source",                     /* PT_iil */
  180.    "Selective list of identifiers in list of identifiers",      /* PT_sli */
  181.    "Rising line number references in list of identifiers",      /* PT_iln */
  182.  
  183.    /* ______ Kall-sekvenser: ______ */
  184.    "Include list of calling sequences in source",               /* PT_csi */
  185.    "Include external functions in list of calling sequences",   /* PT_cie */
  186.    "Use graphical characters in list of calling sequences",     /* PT_csg */
  187.    "Format of list of calling sequences (1=List, 2=Flowchart)", /* PT_csf */
  188.    "Width of indents in list of calling sequences",             /* PT_cwi */
  189.    "Include index register of calling sequences",               /* PT_cir */
  190.    "Default top level function in list of calling sequences",   /* PT_cdt */
  191.  
  192.    /* ______ Linjeinformasjon: ______ */
  193.    "Include source lines information",                          /* PT_ili */
  194.    "Report local linenumber of each source line",               /* PT_lll */
  195.    "Report level of block indention",                           /* PT_rbi */
  196.    "Report each comment line in source",                        /* PT_lcl */
  197.    "Include information about each function in source",         /* PT_lfi */
  198.    "Report number of lines in each function in source",         /* PT_LLF */
  199.    "Report number of empty lines in each function in source",   /* PT_LEF */
  200.    "Report number of comments in each function in source",      /* PT_LCF */
  201.    "Report number of code lines in each function in source",    /* PT_LCO */
  202.    "Report number of comment lines in each function in source", /* PT_LCC */
  203.    "Report list of callers of each function in source",         /* PT_LLC */
  204.  
  205.    /* ______ Diverse: ______ */
  206.    "Source string to reqognice as new-page-string",             /* PT_NPs */
  207.    "Convert new-page-string to a new-page char",                /* PT_NPS */
  208.    "Insert new-page char before each function",                 /* PT_NFU */
  209.    "Insert new-page char between each map section",             /* PT_NFI */
  210.    "Column separator (1=space, 2=tab)",                         /* PT_cse */
  211.    "Delete temporary .smo-files after use",                     /* PT_dtu */
  212.    "Put all added information within C-style comment blocks",   /* PT_gcb */
  213.    "Width of tabulator",                                        /* PT_tab */
  214.    "Disp. info on screen (0=Nothing,1=Few,2=Normal,3=Detailed)",/* PT_dis */
  215.  
  216.    /* ______ Generer: ______ */
  217.    "What to generate (1=All, 2=Objects, 3=Map)",                /* PT_gen */
  218.    "Method of generator (1=Link, 2=Make, 3=Build)",             /* PT_met */
  219.    "Path to object files (.smo-files)",                         /* PT_pof */
  220.    "Path to map files (.sm-files)",                             /* PT_pmf */
  221.    "Path to temporary files (.tmp-files)",                      /* PT_ptf */
  222.    "Use project file",                                          /* PT_upf */
  223.  
  224.    /* ______ Brytere som bare utf¢res direkte, uten å lagres i valg-fil: */
  225.    "Read and use options from specified text file",             /* PT_uof */
  226.    "Write current options settings to specified text file",     /* PT_wof */
  227.    "Reset all options back to default",                         /* PT_res */
  228.    "User help",                                                 /* PT_hlp */
  229. };
  230.  
  231.  
  232.  
  233.  
  234. char *optblocks[] =
  235. {
  236.    "Header with total information about source",           /* OB_TOTINFO */
  237.    "Register of functions in source",                      /* OB_FUNCREG */
  238.    "List of function calls",                               /* OB_FUNCALL */
  239.    "List of identifiers",                                  /* OB_IDLIST */
  240.    "List of calling sequences",                            /* OB_CALSEQ */
  241.    "Source lines information",                             /* OB_LINEINF */
  242.    "Information about each function in source",            /* OB_FUNCINFO */
  243.    "Various options",                                      /* OB_VARIOUS */
  244.    "How and what to generate",                             /* OB_GENERATE */
  245. };
  246.  
  247.  
  248.  
  249.  
  250. char *fnames[] =
  251. {
  252.    ".c",           /* CSOURCE_EXT */
  253.    ".tmp",         /* SMGTEMP_EXT */
  254.    ".opt",         /* SMGOPTI_EXT */
  255.    ".prj",         /* SMGPRJ_EXT */
  256.    ".smo",         /* SMGOBJC_EXT */
  257.    ".sm",          /* SMGMAPF_EXT */
  258.    ".bak",         /* SMGBACK_EXT */
  259.    "default",      /* DEFOPT_FNAME */
  260. };
  261.  
  262.  
  263.  
  264.  
  265. char _StrErrWarning[]         = "Warning: ";
  266. char _StrErrUnknownOption[]   = "Unknown option: %s\n";
  267. char _StrMSGCOPYRIGHT[]       = "Source Mapper ver. "VERSION" for "PLATFORM". Copyright (C) Leif-Erik Larsen, 2000.";
  268. char _StrMSGTEMPFILEID[]      = "Source Mapper ver. "VERSION" for "PLATFORM". Objectfile.\n";
  269. char _StrMSGPRJFILEID[]       = "Source Mapper ver. "VERSION" for "PLATFORM". Projectfile.\n";
  270. char _StrMSGUSAGE[]           = "Usage: sm [Option1] [Option2] ... Source1 [Source2] ...\nFor help on availible options, type 'sm hlp[]'\n";
  271. char _StrMSGINTERPRETLIN[]    = "Scanning lines in source";
  272. char _StrMSGSORTFUNCREG[]     = "Sorting functions";
  273. char _StrMSGSORTIDLST[]       = "Sorting identifiers";
  274. char _StrMSGSORTFCALLST[]     = "Sorting function calls";
  275. char _StrMSGINCLFUNDATA[]     = "Collecting functions";
  276. char _StrMSGINCLLINEINFO[]    = "Collecting data about lines";
  277. char _StrMSGINCLIDDATA[]      = "Collecting identifiers";
  278. char _StrMSGINCLFCALDATA[]    = "Collecting function calls";
  279. char _StrMSGMAKEDIFIDF[]      = "Finding identifiers";
  280. char _StrMSGMAKEDIFFCALF[]    = "Finding function calls";
  281. char _StrMSGMAKINDXFCAL[]     = "Indexing function calls";
  282. char _StrMSGMAKINDXIDLST[]    = "Indexing identifiers";
  283. char _StrMSGTOTINF_SNAME[]    = "Sourcefile";
  284. char _StrMSGTOTINF_LINTOT[]   = "Total number of lines";
  285. char _StrMSGTOTINF_EMPLIN[]   = "Empty lines";
  286. char _StrMSGTOTINF_COMLIN[]   = "Commentlines";
  287. char _StrMSGTOTINF_CODLIN[]   = "Lines with code";
  288. char _StrMSGTOTINF_FUNTOT[]   = "Functions";
  289. char _StrMSGTOTINF_COMENT[]   = "Blocks of comment";
  290. char _StrMSGTOTALYSTR[]       = "Totaly";
  291. char _StrMSGGENERATESOBJ[]    = "Generating object file(s)";
  292. char _StrMSGGENERATESMAP[]    = "Generating map";
  293. char _StrMSGINCLTOTINFO[]     = "Making total information";
  294. char _StrMSGGLOBLINSTART[]    = "Glob.lin.";
  295. char _StrMSGINCLFUNCREG[]     = "Making register of functions";
  296. char _StrMSGFUNCREGSTR[]      = "Index of functions";
  297. char _StrMSGNOFUNCTIONS[]     = "No functions";
  298. char _StrMSGTOTFUNCTIONS[]    = "Total number of functions";
  299. char _StrMSGINCLFUNCALLST[]   = "Making list of function calls";
  300. char _StrMSGFUNCALLSTSTR[]    = "List of function calls";
  301. char _StrMSGSELFUNCALLSTSTR[] = "Selective list of function calls";
  302. char _StrMSGTOTFUNCCALS[]     = "Total number of blocks with function calls in the list";
  303. char _StrMSGIDLSTSTR[]        = "List of identifiers";
  304. char _StrMSGSELIDLSTSTR[]     = "Selective list of identifiers";
  305. char _StrMSGTOTIDS[]          = "Total number of identifiers in the list";
  306. char _StrMSGINCLIDLST[]       = "Including list of identifiers";
  307. char _StrMSGINCLINEINFO[]     = "Source code and line information";
  308. char _StrMSGSOURCECODEINF[]   = "Source with lineinfo";
  309. char _StrMSGONLYCOMENT[]      = "Comment";
  310. char _StrMSGLISTOFCALLERS[]   = "List of callers of";
  311. char _StrMSGGENERALFUNCINF[]  = "General info about";
  312. char _StrMSGFUNCINF_LINTOT[]  = "Total number of lines";
  313. char _StrMSGFUNCINF_LINEMP[]  = "Empty lines";
  314. char _StrMSGFUNCINF_LINCOM[]  = "Commentlines";
  315. char _StrMSGFUNCINF_LINCOD[]  = "Lines with code";
  316. char _StrMSGFUNCINF_CBLOCS[]  = "Blocks of comment";
  317. char _StrMSGNOBODYCALLFUNC[]  = "No caller";
  318. char _StrMSGSEEKTPLEVELF[]    = "Searching for top level function(s)";
  319. char _StrMSGNOTOPLEVELFUNC[]  = "Warning! No top level function. Tries to use default!";
  320. char _StrMSGFLOWCLSTSTR[]     = "List of calling sequences";
  321. char _StrMSGINCLFLOWC[]       = "Making list of calling sequences";
  322. char _StrMSGEXTERNAL[]        = "External";
  323. char _StrMSGFLOWGENSTRIP[]    = "Making stripped references of all calling references";
  324. char _StrMSGSORTFLOWIDXREG[]  = "Sorting index of calling secuences";
  325. char _StrMSGINCLFLOWIDXREG[]  = "Making index of calling sequences";
  326. char _StrMSGIDXREGFLOW[]      = "Index to list of calling sequences";
  327.  
  328.  
  329.  
  330.  
  331. void ErrorShow ( void )
  332. {
  333.    switch (Error.iErr)
  334.    {
  335.       case   0: DoError ("%s",          ErrMsg[  0].pMsg); break;
  336.       case   1: DoError ("%s (%s)",     ErrMsg[  1].pMsg, Error.cFName); break;
  337.       case   2: DoError ("%s (%s)",     ErrMsg[  2].pMsg, Error.cFName); break;
  338.       case   3: DoError ("%s (%s)",     ErrMsg[  3].pMsg, Error.cFName); break;
  339.       case   4: DoError ("%s (%s)",     ErrMsg[  4].pMsg, Error.cFName); break;
  340.       case   5: DoError ("%s",          ErrMsg[  5].pMsg); break;
  341.       case   6: DoError ("%s (%s)",     ErrMsg[  6].pMsg, Error.cFName); break;
  342.       case   7: DoError ("%s",          ErrMsg[  7].pMsg); break;
  343.       case   8: DoError ("%s",          ErrMsg[  8].pMsg); break;
  344.       case   9: DoError ("%s %s",       ErrMsg[  9].pMsg, Error.cFName); break;
  345.       case  10: DoError ("%s",          ErrMsg[ 10].pMsg); break;
  346.       case  11: DoError ("%s (%s)",     ErrMsg[ 11].pMsg, Error.cFName); break;
  347.       case  12: DoError ("%s (%s)",     ErrMsg[ 12].pMsg, Error.cFName); break;
  348.       case  13: DoError ("%s (%s)",     ErrMsg[ 13].pMsg, Error.cFName); break;
  349.       case  14: DoError ("%s",          ErrMsg[ 14].pMsg); break;
  350.       case  15: DoError ("%s (%s)",     ErrMsg[ 15].pMsg, Error.cFName); break;
  351.       case  16: DoError ("%s (%s)",     ErrMsg[ 16].pMsg, Error.cFName); break;
  352.       case  17: DoError ("%s (%s)",     ErrMsg[ 17].pMsg, Error.cFName); break;
  353.       case  18: DoError ("%s",          ErrMsg[ 18].pMsg); break;
  354.       case  19: DoError ("%s (%s)",     ErrMsg[ 19].pMsg, Error.cFName); break;
  355.       case  20: DoError ("%s %d. (%s)", ErrMsg[ 20].pMsg, MAXINLIN, Error.cFName); break;
  356.       case  21: DoError ("%s (%s)",     ErrMsg[ 21].pMsg, Error.cFName); break;
  357.       case  22: DoError ("%s (%s)",     ErrMsg[ 22].pMsg, Error.cFName); break;
  358.       case  23: DoError ("%s (%s)",     ErrMsg[ 23].pMsg, Error.cFName); break;
  359.       case  24: DoError ("%s (%s)",     ErrMsg[ 24].pMsg, Error.cFName); break;
  360.       case  25: DoError ("%s",          ErrMsg[ 25].pMsg, Error.cFName); break;
  361.       case  26: DoError ("%s %s",       ErrMsg[ 26].pMsg, Error.cFName); break;
  362.       case  27: DoError ("%s %d.",      ErrMsg[ 27].pMsg, MAXFUNCN); break;
  363.       case  28: DoError ("%s %d.",      ErrMsg[ 28].pMsg, MAXFUNCN); break;
  364.    }
  365. } /* ErrorShow (); */
  366.  
  367.  
  368.  
  369.  
  370. int ErrorClear ( void )
  371. /* Clear the error code used by our program, making it possible to record
  372.    another error status later.
  373.    Return: Previous error code. */
  374. {
  375.    int iRet = Error.iErr;
  376.  
  377.    _iErrNo = 0;
  378.    memset (&Error, 0, sizeof (Error));
  379.  
  380.    return iRet;
  381. } /* ErrorClear (); */
  382.  
  383.  
  384.  
  385.  
  386. int ErrorSet ( int iErrCode, const char *pFName,
  387.                              const char *pSFileName, int iSFileLNr )
  388. /* Record specified error.
  389.    iErrCode   = Actual errro code (see static structure ErrMsg).
  390.    pFName     = Name of the file that caused the error, or NULL if no such file.
  391.    pSFileName = Name of the source file that called this function (__FILE__).
  392.    pSFileLNr  = Line number of source file where this function was
  393.                 called (__LINE__).
  394.    Return: Previous error code. */
  395. {
  396.    int iRet = Error.iErr;
  397.  
  398.    if (Error.iErr)
  399.       return iRet;                     /* Error has already been recorded */
  400.  
  401.    Error.iErr       = iErrCode;
  402.    Error.errno      = _iErrNo;
  403.    Error.pSFileName = (char*) pSFileName;
  404.    Error.iSFileLNr  = iSFileLNr;
  405.  
  406.    if (pFName)
  407.       strcpy (Error.cFName, pFName);
  408.  
  409.    if (iErrCode == 7  ||     /* Conflictiong options ... */
  410.        iErrCode == 8  ||     /* Unknown generate method! */
  411.        iErrCode == 9  ||     /* Illegal name of SM executable file! */
  412.        iErrCode == 10 ||     /* To many arguments from system! */
  413.        iErrCode == 17 ||     /* Unknown or illegal argument of option! */
  414.        iErrCode == 18 ||     /* Only one sourcefile can bee specified ... */
  415.        iErrCode == 19 ||     /* Unknown option or switch! */
  416.        iErrCode == 20 ||     /* To long line in source! */
  417.        iErrCode == 21 ||     /* To many block levels in source */
  418.        iErrCode == 25 ||     /* Illegal level of block */
  419.        iErrCode == 27 ||     /* Function name is to long */
  420.        iErrCode == 28)       /* Identifier name is to long */
  421.    {
  422.       /* The specified error is of a type that the system doesn't know. */
  423.       Error.errno = 0;
  424.    }
  425.  
  426.    return iRet;
  427. } /* ErrorSet (); */
  428.  
  429.  
  430.  
  431.  
  432. void DoError ( const char *format, ... )
  433. /* Opprettet: Onsdag 21. april 1993.
  434.    Parameter: "format"  Formatstreng for feilmelding.
  435.               "..."     Feilmelding til bruker.
  436.    Retur    :
  437.    Beskriv  : Viser oppgitt advarsel på sjkerm. Inkluderer et linjeskift
  438.               både forran og etter den oppgitte feilmeldingen.
  439. */
  440. {
  441.    va_list argp;                       /* Peker til aktiv parameter */
  442.  
  443.    printf ("\n"
  444.            "Error: ");
  445.  
  446.    va_start (argp, format);            /* Initialiserer "argpek" */
  447.    vprintf  (format, argp);            /* Skriv oppgitte strenger, til bruker*/
  448.    va_end   (argp);                    /* Avslutter alle parameterne */
  449.  
  450.    printf ("\n"
  451.            "\n"
  452.            "    Error #: %d\n"
  453.            "  SM module: %s\n"
  454.            "  SM line #: %d\n"
  455.            "Msg from OS: %d = %s\n"
  456.            "\n",
  457.  
  458.            Error.iErr,
  459.            Error.pSFileName ? Error.pSFileName : "N/A",
  460.            Error.iSFileLNr,
  461.            Error.errno,
  462.            Error.errno ? strerror (Error.errno) : "None");
  463.  
  464.    return;
  465. } /* DoError (); */
  466.  
  467.  
  468.  
  469.  
  470. void DoWarning ( const char *format, ... )
  471. /*  Function: Show specified warning message on display.
  472.    Opprettet: L¢rdag 21. oktober 1995.
  473.    Parameter: "format"  Formatstreng for feilmelding.
  474.               "..."     Feilmelding til bruker.
  475. */
  476. {
  477.    va_list argp;            /* Peker til aktiv parameter */
  478.    printf (_StrErrWarning);
  479.    va_start (argp, format); /* Initialiserer "argpek" */
  480.    vprintf (format, argp);  /* Skriv oppgitte strenger, til bruker*/
  481.    va_end (argp);           /* Avslutter alle parameterne */
  482. } /* DoWarning (); */
  483.  
  484.  
  485.  
  486.  
  487. void SMHelpCmd ( const char *pStrHelp )
  488. {
  489.    if (strcmp (pStrHelp, "") == 0)
  490.    {
  491.       printf ("Here is a list of some frequently used options:\n"
  492.               "\n"
  493.               "%s[+/-] %s\n"
  494.               "%s[+/-] %s\n"
  495.               "%s[+/-] %s\n"
  496.               "%s[+/-] %s\n"
  497.               "%s[+/-] %s\n"
  498.               "%s[+/-] %s\n"
  499.               "%s[+/-] %s\n"
  500.               "%s[+/-] %s\n"
  501.               "%s[...] %s\n"
  502.               "%s[...] %s\n"
  503.               "\n"
  504.               "( --- Note: All options are case significant --- )\n"
  505.               "\n"
  506.               "You can type 'sm hlp[more]' to get more help.\n",
  507.               ptbl[PT_iti], defoptcom[PT_iti],
  508.               ptbl[PT_ifr], defoptcom[PT_ifr],
  509.               ptbl[PT_ilf], defoptcom[PT_ilf],
  510.               ptbl[PT_iil], defoptcom[PT_iil],
  511.               ptbl[PT_csi], defoptcom[PT_csi],
  512.               ptbl[PT_cir], defoptcom[PT_cir],
  513.               ptbl[PT_ili], defoptcom[PT_ili],
  514.               ptbl[PT_lfi], defoptcom[PT_lfi],
  515.               ptbl[PT_uof], defoptcom[PT_uof],
  516.               ptbl[PT_wof], defoptcom[PT_wof]);
  517.    }
  518.  
  519.    else
  520.    if (strcmp (pStrHelp, "more") == 0)
  521.    {
  522.       printf ("Look at the contents of the file '%s%s' to get a short\n"
  523.               "description of every documented option. If you don't have any such file in\n"
  524.               "your directory, type 'sm wof[]' to let SM create it for you. This option\n"
  525.               "file will be loaded automatically each time SM is executed. Therefore, you\n"
  526.               "can edit the contents of this file to change the default settings of SM.\n"
  527.               "\n"
  528.               "Some options are not listed in the file '%s%s'. Those are the\n"
  529.               "options which are executed directly when you specify them, without being\n"
  530.               "stored as real options in the memory of SM. Here you have a list of them:\n"
  531.               "\n"
  532.               "%s[...] %s\n"
  533.               "%s[...] %s\n"
  534.               "%s[]    %s\n"
  535.               "%s[]    %s\n",
  536.               fnames[DEFOPT_FNAME], fnames[SMGOPTI_EXT],
  537.               fnames[DEFOPT_FNAME], fnames[SMGOPTI_EXT],
  538.               ptbl[PT_uof], defoptcom[PT_uof],
  539.               ptbl[PT_wof], defoptcom[PT_wof],
  540.               ptbl[PT_res], defoptcom[PT_res],
  541.               ptbl[PT_hlp], defoptcom[PT_hlp]);
  542.    }
  543.  
  544.    else
  545.    {
  546.       printf ("Unknown help string: %s\n", pStrHelp);
  547.    }
  548. } /* SMHelpCmd (); */
  549.  
  550.  
  551.  
  552.  
  553. void ClrLin ( void )
  554. /* Opprettet: S¢ndag 6. juni 1992.
  555.    Beskriv  : T¢mmer hele linjen hvor cursor befinner seg.
  556.               Cursoren plasseres inntill venstre bildekant.
  557. */
  558. {
  559.    Display (D_HEIGHEST, "");
  560. } /* ClrLin (); */
  561.  
  562.  
  563.  
  564.  
  565. void ClrEOL ( void )
  566. /* Created: Tirsdag 29. september 1992.
  567.    Beskriv: T¢mmer resten av linjen hvor cursor befinner seg.
  568.             Cursoren flyttes ikke.
  569. */
  570. {
  571.    #if __IBMC__ || __IBMCPP__
  572.  
  573.    /* I couldn't find any clreol() in the Visual Age C++ library, so I had
  574.       to hack this little temporary uggly code... */
  575.  
  576.    static int iWasHere = FALSE;
  577.    static int iNrOfColumns = 0;
  578.    int iC1;
  579.    char cStr[256];
  580.    USHORT Row;
  581.    USHORT Col;
  582.    VIOMODEINFO vinfo;
  583.  
  584.    if (!iWasHere)
  585.    {
  586.       iWasHere = TRUE;
  587.       vinfo.cb = sizeof (vinfo);
  588.       VioGetMode (&vinfo, (HVIO) 0);
  589.       iNrOfColumns = vinfo.col;
  590.       if (iNrOfColumns >= sizeof (cStr))
  591.          iNrOfColumns = sizeof (cStr) - 1;
  592.       iNrOfColumns -= 1; /* Don't print to rightmost column */
  593.    }
  594.  
  595.    VioGetCurPos (&Row, &Col, (HVIO) 0);
  596.    for (iC1 = 0; iC1 < iNrOfColumns - Col; cStr[iC1++] = ' ');
  597.    cStr[iC1] = '\0';
  598.    printf (cStr);
  599.    VioSetCurPos (Row, Col, (HVIO) 0);
  600.  
  601.    #else
  602.    clreol ();
  603.    #endif
  604. } /* ClrEOL (); */
  605.  
  606.  
  607.  
  608.  
  609. int Display ( DISP_PRIORITY iPriority, const char *format, ... )
  610. /*
  611.     Function: Display a string on current line on display.
  612.         Date: April, 26. 1993. 13:05. By LEL.
  613.    Interface: iPriority = Priority level of message to display. This value
  614.                           is used to filter how important the message is, and
  615.                           compare that to the optioned message level
  616.                           specified by the user.
  617.               format    = Format string, as in 'printf ()' function.
  618.               ...       = List og arguments.
  619.      Returns: Number of written characters.
  620. */
  621. {
  622.    int count;
  623.    va_list argptr;
  624.  
  625.    switch (o_various.iShowInfo)
  626.    {
  627.       case 0:  /* Nothing */
  628.                return 0;
  629.  
  630.       case 1:  /* Few */
  631.                if (iPriority < D_HEIGHEST)
  632.                   return 0;
  633.  
  634.       case 2:  /* Normal */
  635.                if (iPriority < D_HEIGH)
  636.                   return 0;
  637.  
  638.       case 3:  /* Detailed */
  639.                if (iPriority < D_LOW)
  640.                   return 0;
  641.    }
  642.  
  643.    printf ("\r"); /* Position cursor on first column */
  644.  
  645.    va_start (argptr, format);
  646.    count = vprintf (format, argptr);
  647.    va_end (argptr);
  648.  
  649.    ClrEOL ();
  650.  
  651.    return (count);
  652. } /* Display (); */
  653.  
  654.  
  655.  
  656.  
  657. void *Alloc ( long size )
  658. /*
  659.     Function: Allocates memory from heap.
  660.         Date: March, 17. 1993. LEL.
  661.    Interface: size = Number of bytes to allocate.
  662.      Returns: A pointer to the allocated memory-block.
  663.               A NULL pointer if out of memory.
  664. */
  665. {
  666.    if (size <= 0)
  667.    {
  668.       ERRORSET (5, NULL); /* A rare error that should never happen! */
  669.       return NULL;
  670.    }
  671.  
  672.    #if defined (__GNUC__) || defined (__OS2__)
  673.    return (calloc (size, sizeof (char)));
  674.    #else
  675.    return (farcalloc (size, sizeof (char)));
  676.    #endif
  677. } /* Alloc (); */
  678.  
  679.  
  680.  
  681.  
  682. void Free ( void *buff )
  683. /* Function: Gives allocated memory-block back to heap.
  684.        Date: March, 17. 1993. By LEL. */
  685. {
  686.    if (buff == NULL)
  687.       return;
  688.  
  689.    #if defined (__GNUC__) || defined (__OS2__)
  690.    free (buff);
  691.    #else
  692.    farfree (buff);
  693.    #endif
  694. } /* Free (); */
  695.  
  696.  
  697.  
  698.  
  699. long MemLeft ( void )
  700. /* Created: Fredag 16. october 1992.
  701.    Return : Size of the largest free memory pool in heap. */
  702. {
  703.    #if defined (__GNUC__) || defined (__OS2__) || defined (__WIN32__)
  704.    long ret = 0x7FFFFFFF;        /* 32 bits ==> "Unlimited" memory heap */
  705.    #else
  706.    long ret = farcoreleft ();
  707.    #endif
  708.    return (ret);
  709. } /* MemLeft (); */
  710.  
  711.  
  712.  
  713.  
  714. char *Adress ( char *buff, long index, int esize )
  715. /*
  716.     Function: Calculate the physical address of indexed element in buffer.
  717.         Date: April, 29. 1993. 03:40. By LEL.
  718.    Interface: buff  = Address of buffer witch is to be indexed.
  719.               index = Index to element in buffer (0..).
  720.               esize = Size of each element in buffer. Size must be
  721.                       specified with number of bytes.
  722.      Returns: Address to indexed element in buffer.
  723.      Comment: This function is included for use when need to access
  724.               data in buffer which is larger than 64K.
  725. */
  726. {
  727.    char huge *ret;
  728.  
  729.    ret  = buff;
  730.    ret += index * esize;
  731.  
  732.    return ((char far *) ret);
  733. } /* Adress (); */
  734.  
  735.  
  736.  
  737.  
  738. int MakeMapFiles ( int job, const char *path )
  739. /*
  740.     Function: Make map files and eventually objectfiles of files
  741.               specified by filename with wildcharacters.
  742.         Date: Februar, 23. 1992. By LEL.
  743.    Interface: "job"  PRJMAKE, PRJBUILD or PRJLINK.
  744.               "path" Path and name of files.
  745.      Returns: E/O.
  746. */
  747. {
  748.    int       countf = 0;               /* Teller filer som passer jokerfil */
  749.    char      wildchrf [MAXPATH + 1];   /* Navn til joker-fil */
  750.    char      sfname [MAXPATH + 1];     /* Navn m/katalog til kildefil */
  751.    prjfeTYPE fdata;                    /* Mellomlager for kildefildata */
  752.  
  753.    #if __IBMC__ || __IBMCPP__
  754.    APIRET rc;
  755.    HDIR FindHandle = HDIR_CREATE;
  756.    ULONG ulFindCount = 1;              /* Don't read more than one filename at once */
  757.    FILEFINDBUF3 FFBuff;                /* File Info including size of EA's */
  758.    #define isDONE (rc != NO_ERROR)
  759.    #define thisFILENAME (FFBuff.achName)
  760.    #define isLEGALFILE (!(FFBuff.attrFile & FILE_DIRECTORY))
  761.    #else
  762.    int done;
  763.    struct ffblk _ffblk;                /* DOS file control block structure */
  764.    #define isDONE (done)
  765.    #define thisFILENAME (_ffblk.ff_name)
  766.    #define isLEGALFILE (!((_ffblk.ff_attrib & FA_LABEL) || (_ffblk.ff_attrib & FA_DIREC)))
  767.    #endif
  768.  
  769.    strcpy (wildchrf, path);            /* Lagre navn til joker-fil */
  770.    strcpy (sfname, path);              /* Lagre katalog til kildefil(er) */
  771.  
  772.    #if __IBMC__ || __IBMCPP__
  773.    rc = DosFindFirst ("*.*", &FindHandle,
  774.                       FILE_ARCHIVED | FILE_SYSTEM | FILE_READONLY | FILE_HIDDEN,
  775.                      (PVOID) &FFBuff,
  776.                       sizeof (FFBuff), &ulFindCount, FIL_STANDARD);
  777.    #else
  778.    done = findfirst (path, &_ffblk, 0);
  779.    #endif
  780.    while (!isDONE)                     /* Loop through findnext until done */
  781.    {
  782.       if (isLEGALFILE)                 /* Ignore directories */
  783.       {
  784.          countf += 1;                  /* Teller antall matchende filnavn */
  785.  
  786.          ResetPrjStat ();              /* Resett prosjekt-status */
  787.          ResetPrjFETYPE (&fdata);      /* Resett prosjekt-data */
  788.  
  789.          CutFName (sfname);            /* Slett filnavn del av katalog */
  790.          Slash (sfname);
  791.          strcat (sfname, thisFILENAME);/* Konstruer fullt navn til kildefil */
  792.  
  793.          strcpy (fdata.name, sfname);  /* Lagre kildefilnavn til prosjekt */
  794.  
  795.          strcpy (fdata.objn, sfname);  /* Lagre navn til objektfilen også */
  796.          CutFExt (fdata.objn);
  797.          strcat (fdata.objn, fnames[SMGOBJC_EXT]);
  798.  
  799.          /* Lagre informasjon om denne kildemodulen til aktiv prosjektfil */
  800.          if (!AddFDataToPrj (&fdata))
  801.          {
  802.             #if __IBMC__ || __IBMCPP__
  803.             DosFindClose (FindHandle);
  804.             #endif
  805.             RETURN_ERR;
  806.          }
  807.  
  808.          if (job != PRJLINK)           /* Hvis kartet ikke bare skal linkes */
  809.             if (!ScanFilesInPrj (job)) /* Utf¢r scan av aktiv/eneste kildefil*/
  810.                RETURN_ERR;
  811.  
  812.          if (o_generate.gen != O_TEMP) /* Hvis mer skal gj¢res enn scan */
  813.             if (!MakeMapFile ())       /* Produser selve kartfilen */
  814.                RETURN_ERR;
  815.  
  816.          printf ("\n\n");              /* To linjeskift mellom hver kildefil */
  817.       }
  818.  
  819.       #if __IBMC__ || __IBMCPP__
  820.       rc = DosFindNext (FindHandle, (PVOID) &FFBuff, sizeof (FFBuff), &ulFindCount);
  821.       #else
  822.       done = findnext (&_ffblk);
  823.       #endif
  824.    }
  825.  
  826.    #if __IBMC__ || __IBMCPP__
  827.    DosFindClose (FindHandle);
  828.    #else
  829.    #endif
  830.  
  831.    if (countf == 0)                    /* Hvis ingen filnavn er funnet totalt*/
  832.       RETERR (1, path);                /* Ingen matchende filnavn */
  833.  
  834.    return (OK);                        /* Vellykket kartgenerasjon */
  835. } /* MakeMapFiles (); */
  836.  
  837.  
  838.  
  839.  
  840. int RemoveAllSmg ( void )
  841. /* Date: February 08, 1996. By LEL.
  842.    Delete all .smg-files. Call this upon termination of SM, if user want
  843.    us to do it (via user options) */
  844. {
  845.    int c1;
  846.    prjfeTYPE fdata;
  847.  
  848.    for (c1 = 1; c1 <= prjstat.filc; c1++) /* All sources in project */
  849.    {
  850.       if (!GetFDataFromPrj (c1, &fdata))  /* Get name of source file in projec*/
  851.          RETURN_ERR;
  852.       Remove (fdata.objn);                /* Delete this .smg-file */
  853.    }
  854.  
  855.    return OK;
  856. } /* RemoveAllSmg (); */
  857.  
  858.  
  859.  
  860.  
  861. void CallWhenExit ( void )
  862. /*
  863.     Function: Allways call this function before termiante.
  864.         Date: 1992. By LEL.
  865.      Comment: To force a call of this function whenever the program
  866.               terminate, add it to the quew of functions to call when
  867.               exit by calling the standard ANSI C function 'atexit ()'.
  868. */
  869. {
  870.    if (o_various.del)                  /* If we shall delete all .smg-files  */
  871.       RemoveAllSmg ();                 /* Delete all .smg-files of prj */
  872.  
  873.    #if __IBMC__ || __IBMCPP__
  874.    _fcloseall ();
  875.    #elif __GNUC__
  876.    FCloseAll ();
  877.    #else
  878.    fcloseall ();
  879.    #endif
  880.  
  881.    Remove (tmpn.funcal);               /* Temporary file of function calls   */
  882.    Remove (tmpn.lininf);               /* Temporary file of line information */
  883.    Remove (tmpn.funreg);               /* Temporary file of function register*/
  884.    Remove (tmpn.idlist);               /* Temporary file of items            */
  885.    Remove (tmpn.manobj);               /* Temporary main objectfile          */
  886.    Remove (tmpn.sortfi);               /* Temporary file used when sorting   */
  887.    Remove (tmpn.indexf);               /* Temporary file used to index data  */
  888.  
  889.    if (prjstat.temp)                   /* Is active project temporary?       */
  890.    {
  891.       if (prjstat.name[0])             /* If this filename has been created  */
  892.          Remove (prjstat.name);        /* Yes, delete temoprary projectfile  */
  893.       else
  894.          Remove (tmpn.projec);         /* Delete default temporary projectf. */
  895.    }
  896. } /* CallWhenExit (); */
  897.  
  898.  
  899.  
  900.  
  901. int CallWhenCtrlBrk ( void )
  902. /*
  903.     Function: Call this function whenever user press control-break on
  904.               keyboard. Also call upon any critical errors, such as divide
  905.               by zero.
  906.         Date: September 22, 1992. By LEL.
  907.      Returns: A dummy value 0.
  908.      Comment: To force a call to this function when user press control-
  909.               break, use the function 'ctrlbrk ()'.
  910. */
  911. {
  912.    char mapname [MAXPATH + 1];  /* Name of map file */
  913.  
  914.    Display (D_HEIGHEST,
  915.             "\n"
  916.             "\n"
  917.             "Oups! <Control-C> or <Control-Break> detected.\n"
  918.             "Cleaning up and terminating the program...\n");
  919.  
  920.    FCloseAll ();                /* Close all open files */
  921.  
  922.    MakeMapName (mapname);       /* Get name of the map file */
  923.    Remove (mapname);            /* Delete unfinished map file */
  924.  
  925.    exit (-1);                   /* Call CallWhenExit() and abort the program */
  926.  
  927.    return (0);                  /* Return dummy 0, to satisfy caller */
  928. } /* CallWhenCtrlBrk (); */
  929.  
  930.  
  931.  
  932.  
  933. #if defined (__GNUC__) || defined (__WIN32__)
  934. #pragma argsused
  935. void CatchSignal ( int iType )
  936. {
  937.    signal (SIGINT, CatchSignal);  /* Reinstall the signal handler (!!!) */
  938.    CallWhenCtrlBrk ();
  939. }
  940. #endif
  941.  
  942.  
  943.  
  944.  
  945. #ifdef __OS2__
  946. #pragma argsused
  947. ULONG _cdecl ExceptRoutine ( PEXCEPTIONREPORTRECORD pExRep,
  948.                              PEXCEPTIONREGISTRATIONRECORD pExReg,
  949.                              PCONTEXTRECORD pContext, PVOID pVoid )
  950. /* Exception handler for OS/2. This will be called whenever user
  951.    press Ctrl-C or Ctrl-Break. */
  952. {
  953.    static int iIsHere = FALSE;
  954.  
  955.    if (pExRep->ExceptionNum == XCPT_SIGNAL)
  956.    {
  957.       if (!iIsHere)  /* Prevent reqursive exception handling upon exit (); */
  958.       {
  959.          iIsHere = TRUE;
  960.          CallWhenCtrlBrk (); /* This statement will never return ... */
  961.          iIsHere = FALSE;
  962.       }
  963.    }
  964.  
  965.    return (XCPT_CONTINUE_SEARCH);
  966. }
  967. #endif
  968.  
  969.  
  970.  
  971.  
  972. int RunCLineVer ( char *param )
  973. /*
  974.     Function: Main interface to command line version of source map
  975.               generator (SMG).
  976.         Date: February, 4. 1993.
  977.    Interface: param = Argument from DOS, converted to a single string.
  978.      Returns: E/O.
  979. */
  980. {
  981.    int       c1 = 0;
  982.    int       job;                      /* PRJMAKE/PRJBUILD/PRJLINK */
  983.    prjfeTYPE fdata;                    /* Mellomlager for kildefildata */
  984.    #ifndef REGISTERED
  985.    char *pUnregistered = "THIS COPY ISN'T REGISTERED. PLEASE REGISTER!";
  986.    int iC1, iChkSum;
  987.    for (iC1 = 0, iChkSum = 0;
  988.         iC1 < strlen (pUnregistered);
  989.         iChkSum += pUnregistered[iC1++]);
  990.    if (iChkSum != 3028)
  991.    {
  992.       printf ("This program has been hacked and is therefore unable to run! :-)\n");
  993.       exit (-1);
  994.    }
  995.    printf ("%s\n", pUnregistered);
  996.    #endif
  997.  
  998.    /* Vis hjelp om SMG dersom ingen parametere er oppgitt: */
  999.    if (param[0] == '\0')
  1000.    {
  1001.       printf ("%s\n\n%s", _StrMSGCOPYRIGHT, _StrMSGUSAGE);
  1002.       return (OK);
  1003.    }
  1004.  
  1005.    ResetAllFNames ();                  /* Nullstiller filnavn-lager */
  1006.    ResetPrjStat ();                    /* Initier data om prosjekt */
  1007.  
  1008.    if (!SetDefaultOptions ())          /* Initier brukervalg til standard */
  1009.       RETURN_ERR;
  1010.  
  1011.    /* --- Copyright information --- */
  1012.    Display (D_HEIGHEST, "%s\n\n", _StrMSGCOPYRIGHT);
  1013.  
  1014.    /* Les standard valgfiler (f¢rst fra hjemmekatalogen til sm.exe, deretter
  1015.       fra aktiv katalog hvis den er ulik hjemmekatalogen) */
  1016.    read_default_options ();
  1017.  
  1018.    if (!interpret_parameters (param, FALSE))  /* Translate options from user */
  1019.       RETURN_ERR;
  1020.  
  1021.    if (!SetTmpFNames ())               /* Set and create temporary filenames */
  1022.       RETURN_ERR;
  1023.  
  1024.    if (o_generate.met == O_LINK && o_generate.gen == O_MAP)
  1025.    {
  1026.       /* Conflictiong options: Can't link map without making .SMO-files! */
  1027.       RETERR (7, NULL);
  1028.    }
  1029.  
  1030.    if (prjstat.filc == 0)              /* Any source-files in project?       */
  1031.       return (OK);                     /* No, do not make a map              */
  1032.  
  1033.    while (c1++ < prjstat.filc)         /* Loop trough all sources in project */
  1034.    {
  1035.       if (!GetFDataFromPrj (c1, &fdata)) /* Get name of source file in projec*/
  1036.          RETURN_ERR;
  1037.  
  1038.       /* Construct name of objectfile from name of sourcefile */
  1039.       GetObjFileName (fdata.objn, fdata.name);
  1040.  
  1041.       if (!PutFDataToPrj (c1, &fdata)) /* Update project-info about source   */
  1042.          RETURN_ERR;
  1043.    }
  1044.  
  1045.    switch (o_generate.met)
  1046.    {
  1047.       case O_LINK:           /* Link existing objectfiles to map */
  1048.            job = PRJLINK;
  1049.            break;
  1050.  
  1051.       case O_MAKE:           /* Make only changed source-files */
  1052.            job = PRJMAKE;
  1053.            break;
  1054.  
  1055.       case O_BUILD:          /* Build all objectfiles, and mapfiles */
  1056.            job = PRJBUILD;
  1057.            break;
  1058.  
  1059.       default:               /* Unknown method, return error */
  1060.            RETERR (8, NULL);
  1061.    }
  1062.  
  1063.    if (prjstat.filc == 1)              /* If only one sourcefile in project  */
  1064.    {
  1065.       if (!GetFDataFromPrj (1, &fdata)) /* Get sourcefile info from project  */
  1066.          RETURN_ERR;
  1067.  
  1068.       if (IsWild (fdata.name))         /* Any wildchar in name of sourcefile */
  1069.       {
  1070.          /* Yes, make maps of wildchar-files */
  1071.          if (!MakeMapFiles (job, fdata.name))
  1072.             RETURN_ERR;
  1073.          return (OK);
  1074.       }
  1075.    }
  1076.  
  1077.    if (job != PRJLINK)
  1078.       if (!ScanFilesInPrj (job))
  1079.          RETURN_ERR;
  1080.  
  1081.    if (o_generate.gen != O_TEMP)       /* Ikke hvis bare mellomfil skal lages*/
  1082.       if (!MakeMapFile ())             /* Produser selve kartfilen */
  1083.          RETURN_ERR;
  1084.  
  1085.    if (prjstat.file)                   /* If project file is open */
  1086.    {
  1087.       FClose (prjstat.file);           /* Close it */
  1088.       prjstat.file = NULL;
  1089.    }
  1090.  
  1091.    return (OK);
  1092. } /* RunCLineVer (); */
  1093.  
  1094.  
  1095.  
  1096.  
  1097. int mainCLineVer ( int argc, char *argv[] )
  1098. /*
  1099.         Date: April, 7. 1992.
  1100.    Interface: argc = Number of strings in 'argv' from DOS.
  1101.               argv = Table of argument strings from DOS.
  1102.      Returns: E/O.
  1103. */
  1104. {
  1105.    #ifdef __OS2__
  1106.    struct
  1107.    { PEXCEPTIONREGISTRATIONRECORD pLink;
  1108.      ULONG (_cdecl *pSysEH) (PEXCEPTIONREPORTRECORD,
  1109.                              PEXCEPTIONREGISTRATIONRECORD,
  1110.                              PCONTEXTRECORD, PVOID);
  1111.    } RegRec;                     /* Structure to pass to exception handler */
  1112.    #endif
  1113.    int  c1 = 1;
  1114.    char param [MAXUSERPARAML + 1];
  1115.  
  1116.    setbuf (stdout, NULL);        /* Unbuffered screen output */
  1117.  
  1118.    /* Katalog til SMG1 program-katalog */
  1119.    strcpy (progdir, GetPath (argv[0]));
  1120.  
  1121.    /* Oversett parametere fra kommandolinja, ved å skj¢te dem sammen
  1122.       til én streng: */
  1123.    param [0] = 0;
  1124.    while (c1 < argc)
  1125.    {
  1126.       if (strlen (param) + strlen (argv[c1]) < MAXUSERPARAML - 1)
  1127.       {
  1128.          strcat (param, argv[c1++]);
  1129.          strcat (param, " ");
  1130.       }
  1131.       else
  1132.       {
  1133.          RETERR (10, NULL);      /* To many arguments from DOS */
  1134.       }
  1135.    }
  1136.  
  1137.    #if defined (__GNUC__) || defined (__WIN32__)
  1138.    signal (SIGINT, CatchSignal);
  1139.    #elif __OS2__
  1140.    /* The DosSetExceptionHandler call will link the exception registration
  1141.       record into the chain for the thread */
  1142.    RegRec.pLink = 0;
  1143.    RegRec.pSysEH = ExceptRoutine; /* Pointer to the exception handler */
  1144.    DosSetExceptionHandler ((PEXCEPTIONREGISTRATIONRECORD) &RegRec);
  1145.    #else
  1146.    ctrlbrk (CallWhenCtrlBrk);          /* Sett ctrlbrk-handler */
  1147.    #endif
  1148.  
  1149.    atexit (CallWhenExit);              /* Kall denne funksjonen ved exit */
  1150.  
  1151.    if (!RunCLineVer (param))
  1152.    {
  1153.       #ifdef __OS2__
  1154.       DosUnsetExceptionHandler ((PEXCEPTIONREGISTRATIONRECORD) &RegRec);
  1155.       #endif
  1156.       RETURN_ERR;
  1157.    }
  1158.  
  1159.    #ifdef __OS2__
  1160.    /* Must deregister the exception handler of OS/2 because the exception
  1161.       handler is no longer valid after this function has returned (the handler
  1162.       is part of the call stack) */
  1163.    DosUnsetExceptionHandler ((PEXCEPTIONREGISTRATIONRECORD) &RegRec);
  1164.    #endif
  1165.  
  1166.    return (OK);
  1167. } /* mainCLineVer (); */
  1168.  
  1169.  
  1170.  
  1171.  
  1172. int main ( int argc, char *argv[] )
  1173. /* Return:
  1174.    0 = Success.
  1175.    -1 = Some other error.
  1176.    Else the returned error is a system level error code. */
  1177. {
  1178.    #ifdef __OS2__
  1179.    /* Source Mapper now initialize it self to a lower task priority than
  1180.    is set by default by the system. This is due to the fact that SM is
  1181.    very disk intensive, and thus will perform about as fast even
  1182.    if the priority is relatively low. */
  1183.    DosSetPriority (PRTYS_THREAD,        /* Change a single thread */
  1184.                    PRTYC_IDLETIME,
  1185.                    PRTYD_MAXIMUM,
  1186.                    0L);                 /* Assume current thread  */
  1187.    #endif
  1188.  
  1189.    ErrorClear ();
  1190.    Randomize ();        /* Randomize maker of temporary filenames */
  1191.    if (!mainCLineVer (argc, argv))
  1192.    {
  1193.       ErrorShow ();
  1194.       return (Error.errno ? Error.errno : -1);
  1195.    }
  1196.  
  1197.    return (0);
  1198. } /* main (); */
  1199.  
  1200.