/
dinruspro
/
examples
Обзор
Документация
Войти
/
dinruspro
/
examples
Код
Запросы
0
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
main
idmap/idmap.cpp
46 строк
917 B
EnergonV
Примеры перекочевали в гит-репо (наконец-то!)
09 янв 2024, 19:13
09 янв 2024, 19:13
757fe92
Код
Авторство
О чём код?
#include <Core/Core.h> using namespace Upp; CONSOLE_APP_MAIN { const Vector<String>& arg = CommandLine(); if(arg.GetCount() != 1) { Cout() << "Использование: idmap файл\n"; SetExitCode(1); return; } FileIn in(arg[0]); if(!in) { SetExitCode(2); return; } VectorMap< String, Vector<int> > map; int line = 1; while(!in.IsEof()) { int c = in.Get(); if(isalpha(c) || c == '_') { String id; id.Cat(c); c = in.Get(); while(c > 0 && (isalnum(c) || c == '_')) { id.Cat(c); c = in.Get(); } map.GetAdd(id).Add(line); } else if(c == '\n') line++; } Vector<int> order = GetSortOrder(map.GetKeys()); for(int i = 0; i < order.GetCount(); i++) { Cout() << Format("%-32s: ", ~map.GetKey(order[i])); const Vector<int>& l = map[order[i]]; for(int i = 0; i < l.GetCount(); i++) { if(i) Cout() << ", "; Cout() << l[i]; } Cout() << '\n'; } }